18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * finite state machine for device handling
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *    Copyright IBM Corp. 2002, 2008
68c2ecf20Sopenharmony_ci *    Author(s): Cornelia Huck (cornelia.huck@de.ibm.com)
78c2ecf20Sopenharmony_ci *		 Martin Schwidefsky (schwidefsky@de.ibm.com)
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/module.h>
118c2ecf20Sopenharmony_ci#include <linux/init.h>
128c2ecf20Sopenharmony_ci#include <linux/jiffies.h>
138c2ecf20Sopenharmony_ci#include <linux/string.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <asm/ccwdev.h>
168c2ecf20Sopenharmony_ci#include <asm/cio.h>
178c2ecf20Sopenharmony_ci#include <asm/chpid.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include "cio.h"
208c2ecf20Sopenharmony_ci#include "cio_debug.h"
218c2ecf20Sopenharmony_ci#include "css.h"
228c2ecf20Sopenharmony_ci#include "device.h"
238c2ecf20Sopenharmony_ci#include "chsc.h"
248c2ecf20Sopenharmony_ci#include "ioasm.h"
258c2ecf20Sopenharmony_ci#include "chp.h"
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic int timeout_log_enabled;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic int __init ccw_timeout_log_setup(char *unused)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci	timeout_log_enabled = 1;
328c2ecf20Sopenharmony_ci	return 1;
338c2ecf20Sopenharmony_ci}
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci__setup("ccw_timeout_log", ccw_timeout_log_setup);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cistatic void ccw_timeout_log(struct ccw_device *cdev)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	struct schib schib;
408c2ecf20Sopenharmony_ci	struct subchannel *sch;
418c2ecf20Sopenharmony_ci	struct io_subchannel_private *private;
428c2ecf20Sopenharmony_ci	union orb *orb;
438c2ecf20Sopenharmony_ci	int cc;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
468c2ecf20Sopenharmony_ci	private = to_io_private(sch);
478c2ecf20Sopenharmony_ci	orb = &private->orb;
488c2ecf20Sopenharmony_ci	cc = stsch(sch->schid, &schib);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: ccw device timeout occurred at %llx, "
518c2ecf20Sopenharmony_ci	       "device information:\n", get_tod_clock());
528c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: orb:\n");
538c2ecf20Sopenharmony_ci	print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
548c2ecf20Sopenharmony_ci		       orb, sizeof(*orb), 0);
558c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: ccw device bus id: %s\n",
568c2ecf20Sopenharmony_ci	       dev_name(&cdev->dev));
578c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: subchannel bus id: %s\n",
588c2ecf20Sopenharmony_ci	       dev_name(&sch->dev));
598c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: subchannel lpm: %02x, opm: %02x, "
608c2ecf20Sopenharmony_ci	       "vpm: %02x\n", sch->lpm, sch->opm, sch->vpm);
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	if (orb->tm.b) {
638c2ecf20Sopenharmony_ci		printk(KERN_WARNING "cio: orb indicates transport mode\n");
648c2ecf20Sopenharmony_ci		printk(KERN_WARNING "cio: last tcw:\n");
658c2ecf20Sopenharmony_ci		print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
668c2ecf20Sopenharmony_ci			       (void *)(addr_t)orb->tm.tcw,
678c2ecf20Sopenharmony_ci			       sizeof(struct tcw), 0);
688c2ecf20Sopenharmony_ci	} else {
698c2ecf20Sopenharmony_ci		printk(KERN_WARNING "cio: orb indicates command mode\n");
708c2ecf20Sopenharmony_ci		if ((void *)(addr_t)orb->cmd.cpa ==
718c2ecf20Sopenharmony_ci		    &private->dma_area->sense_ccw ||
728c2ecf20Sopenharmony_ci		    (void *)(addr_t)orb->cmd.cpa ==
738c2ecf20Sopenharmony_ci		    cdev->private->dma_area->iccws)
748c2ecf20Sopenharmony_ci			printk(KERN_WARNING "cio: last channel program "
758c2ecf20Sopenharmony_ci			       "(intern):\n");
768c2ecf20Sopenharmony_ci		else
778c2ecf20Sopenharmony_ci			printk(KERN_WARNING "cio: last channel program:\n");
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci		print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
808c2ecf20Sopenharmony_ci			       (void *)(addr_t)orb->cmd.cpa,
818c2ecf20Sopenharmony_ci			       sizeof(struct ccw1), 0);
828c2ecf20Sopenharmony_ci	}
838c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: ccw device state: %d\n",
848c2ecf20Sopenharmony_ci	       cdev->private->state);
858c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: store subchannel returned: cc=%d\n", cc);
868c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: schib:\n");
878c2ecf20Sopenharmony_ci	print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
888c2ecf20Sopenharmony_ci		       &schib, sizeof(schib), 0);
898c2ecf20Sopenharmony_ci	printk(KERN_WARNING "cio: ccw device flags:\n");
908c2ecf20Sopenharmony_ci	print_hex_dump(KERN_WARNING, "cio:  ", DUMP_PREFIX_NONE, 16, 1,
918c2ecf20Sopenharmony_ci		       &cdev->private->flags, sizeof(cdev->private->flags), 0);
928c2ecf20Sopenharmony_ci}
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/*
958c2ecf20Sopenharmony_ci * Timeout function. It just triggers a DEV_EVENT_TIMEOUT.
968c2ecf20Sopenharmony_ci */
978c2ecf20Sopenharmony_civoid
988c2ecf20Sopenharmony_ciccw_device_timeout(struct timer_list *t)
998c2ecf20Sopenharmony_ci{
1008c2ecf20Sopenharmony_ci	struct ccw_device_private *priv = from_timer(priv, t, timer);
1018c2ecf20Sopenharmony_ci	struct ccw_device *cdev = priv->cdev;
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	spin_lock_irq(cdev->ccwlock);
1048c2ecf20Sopenharmony_ci	if (timeout_log_enabled)
1058c2ecf20Sopenharmony_ci		ccw_timeout_log(cdev);
1068c2ecf20Sopenharmony_ci	dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);
1078c2ecf20Sopenharmony_ci	spin_unlock_irq(cdev->ccwlock);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/*
1118c2ecf20Sopenharmony_ci * Set timeout
1128c2ecf20Sopenharmony_ci */
1138c2ecf20Sopenharmony_civoid
1148c2ecf20Sopenharmony_ciccw_device_set_timeout(struct ccw_device *cdev, int expires)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	if (expires == 0) {
1178c2ecf20Sopenharmony_ci		del_timer(&cdev->private->timer);
1188c2ecf20Sopenharmony_ci		return;
1198c2ecf20Sopenharmony_ci	}
1208c2ecf20Sopenharmony_ci	if (timer_pending(&cdev->private->timer)) {
1218c2ecf20Sopenharmony_ci		if (mod_timer(&cdev->private->timer, jiffies + expires))
1228c2ecf20Sopenharmony_ci			return;
1238c2ecf20Sopenharmony_ci	}
1248c2ecf20Sopenharmony_ci	cdev->private->timer.expires = jiffies + expires;
1258c2ecf20Sopenharmony_ci	add_timer(&cdev->private->timer);
1268c2ecf20Sopenharmony_ci}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ciint
1298c2ecf20Sopenharmony_ciccw_device_cancel_halt_clear(struct ccw_device *cdev)
1308c2ecf20Sopenharmony_ci{
1318c2ecf20Sopenharmony_ci	struct subchannel *sch;
1328c2ecf20Sopenharmony_ci	int ret;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
1358c2ecf20Sopenharmony_ci	ret = cio_cancel_halt_clear(sch, &cdev->private->iretry);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	if (ret == -EIO)
1388c2ecf20Sopenharmony_ci		CIO_MSG_EVENT(0, "0.%x.%04x: could not stop I/O\n",
1398c2ecf20Sopenharmony_ci			      cdev->private->dev_id.ssid,
1408c2ecf20Sopenharmony_ci			      cdev->private->dev_id.devno);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci	return ret;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_civoid ccw_device_update_sense_data(struct ccw_device *cdev)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	memset(&cdev->id, 0, sizeof(cdev->id));
1488c2ecf20Sopenharmony_ci	cdev->id.cu_type = cdev->private->dma_area->senseid.cu_type;
1498c2ecf20Sopenharmony_ci	cdev->id.cu_model = cdev->private->dma_area->senseid.cu_model;
1508c2ecf20Sopenharmony_ci	cdev->id.dev_type = cdev->private->dma_area->senseid.dev_type;
1518c2ecf20Sopenharmony_ci	cdev->id.dev_model = cdev->private->dma_area->senseid.dev_model;
1528c2ecf20Sopenharmony_ci}
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciint ccw_device_test_sense_data(struct ccw_device *cdev)
1558c2ecf20Sopenharmony_ci{
1568c2ecf20Sopenharmony_ci	return cdev->id.cu_type ==
1578c2ecf20Sopenharmony_ci		cdev->private->dma_area->senseid.cu_type &&
1588c2ecf20Sopenharmony_ci		cdev->id.cu_model ==
1598c2ecf20Sopenharmony_ci		cdev->private->dma_area->senseid.cu_model &&
1608c2ecf20Sopenharmony_ci		cdev->id.dev_type ==
1618c2ecf20Sopenharmony_ci		cdev->private->dma_area->senseid.dev_type &&
1628c2ecf20Sopenharmony_ci		cdev->id.dev_model ==
1638c2ecf20Sopenharmony_ci		cdev->private->dma_area->senseid.dev_model;
1648c2ecf20Sopenharmony_ci}
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/*
1678c2ecf20Sopenharmony_ci * The machine won't give us any notification by machine check if a chpid has
1688c2ecf20Sopenharmony_ci * been varied online on the SE so we have to find out by magic (i. e. driving
1698c2ecf20Sopenharmony_ci * the channel subsystem to device selection and updating our path masks).
1708c2ecf20Sopenharmony_ci */
1718c2ecf20Sopenharmony_cistatic void
1728c2ecf20Sopenharmony_ci__recover_lost_chpids(struct subchannel *sch, int old_lpm)
1738c2ecf20Sopenharmony_ci{
1748c2ecf20Sopenharmony_ci	int mask, i;
1758c2ecf20Sopenharmony_ci	struct chp_id chpid;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	chp_id_init(&chpid);
1788c2ecf20Sopenharmony_ci	for (i = 0; i<8; i++) {
1798c2ecf20Sopenharmony_ci		mask = 0x80 >> i;
1808c2ecf20Sopenharmony_ci		if (!(sch->lpm & mask))
1818c2ecf20Sopenharmony_ci			continue;
1828c2ecf20Sopenharmony_ci		if (old_lpm & mask)
1838c2ecf20Sopenharmony_ci			continue;
1848c2ecf20Sopenharmony_ci		chpid.id = sch->schib.pmcw.chpid[i];
1858c2ecf20Sopenharmony_ci		if (!chp_is_registered(chpid))
1868c2ecf20Sopenharmony_ci			css_schedule_eval_all();
1878c2ecf20Sopenharmony_ci	}
1888c2ecf20Sopenharmony_ci}
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/*
1918c2ecf20Sopenharmony_ci * Stop device recognition.
1928c2ecf20Sopenharmony_ci */
1938c2ecf20Sopenharmony_cistatic void
1948c2ecf20Sopenharmony_ciccw_device_recog_done(struct ccw_device *cdev, int state)
1958c2ecf20Sopenharmony_ci{
1968c2ecf20Sopenharmony_ci	struct subchannel *sch;
1978c2ecf20Sopenharmony_ci	int old_lpm;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	if (cio_disable_subchannel(sch))
2028c2ecf20Sopenharmony_ci		state = DEV_STATE_NOT_OPER;
2038c2ecf20Sopenharmony_ci	/*
2048c2ecf20Sopenharmony_ci	 * Now that we tried recognition, we have performed device selection
2058c2ecf20Sopenharmony_ci	 * through ssch() and the path information is up to date.
2068c2ecf20Sopenharmony_ci	 */
2078c2ecf20Sopenharmony_ci	old_lpm = sch->lpm;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci	/* Check since device may again have become not operational. */
2108c2ecf20Sopenharmony_ci	if (cio_update_schib(sch))
2118c2ecf20Sopenharmony_ci		state = DEV_STATE_NOT_OPER;
2128c2ecf20Sopenharmony_ci	else
2138c2ecf20Sopenharmony_ci		sch->lpm = sch->schib.pmcw.pam & sch->opm;
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID)
2168c2ecf20Sopenharmony_ci		/* Force reprobe on all chpids. */
2178c2ecf20Sopenharmony_ci		old_lpm = 0;
2188c2ecf20Sopenharmony_ci	if (sch->lpm != old_lpm)
2198c2ecf20Sopenharmony_ci		__recover_lost_chpids(sch, old_lpm);
2208c2ecf20Sopenharmony_ci	if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID &&
2218c2ecf20Sopenharmony_ci	    (state == DEV_STATE_NOT_OPER || state == DEV_STATE_BOXED)) {
2228c2ecf20Sopenharmony_ci		cdev->private->flags.recog_done = 1;
2238c2ecf20Sopenharmony_ci		cdev->private->state = DEV_STATE_DISCONNECTED;
2248c2ecf20Sopenharmony_ci		wake_up(&cdev->private->wait_q);
2258c2ecf20Sopenharmony_ci		return;
2268c2ecf20Sopenharmony_ci	}
2278c2ecf20Sopenharmony_ci	if (cdev->private->flags.resuming) {
2288c2ecf20Sopenharmony_ci		cdev->private->state = state;
2298c2ecf20Sopenharmony_ci		cdev->private->flags.recog_done = 1;
2308c2ecf20Sopenharmony_ci		wake_up(&cdev->private->wait_q);
2318c2ecf20Sopenharmony_ci		return;
2328c2ecf20Sopenharmony_ci	}
2338c2ecf20Sopenharmony_ci	switch (state) {
2348c2ecf20Sopenharmony_ci	case DEV_STATE_NOT_OPER:
2358c2ecf20Sopenharmony_ci		break;
2368c2ecf20Sopenharmony_ci	case DEV_STATE_OFFLINE:
2378c2ecf20Sopenharmony_ci		if (!cdev->online) {
2388c2ecf20Sopenharmony_ci			ccw_device_update_sense_data(cdev);
2398c2ecf20Sopenharmony_ci			break;
2408c2ecf20Sopenharmony_ci		}
2418c2ecf20Sopenharmony_ci		cdev->private->state = DEV_STATE_OFFLINE;
2428c2ecf20Sopenharmony_ci		cdev->private->flags.recog_done = 1;
2438c2ecf20Sopenharmony_ci		if (ccw_device_test_sense_data(cdev)) {
2448c2ecf20Sopenharmony_ci			cdev->private->flags.donotify = 1;
2458c2ecf20Sopenharmony_ci			ccw_device_online(cdev);
2468c2ecf20Sopenharmony_ci			wake_up(&cdev->private->wait_q);
2478c2ecf20Sopenharmony_ci		} else {
2488c2ecf20Sopenharmony_ci			ccw_device_update_sense_data(cdev);
2498c2ecf20Sopenharmony_ci			ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
2508c2ecf20Sopenharmony_ci		}
2518c2ecf20Sopenharmony_ci		return;
2528c2ecf20Sopenharmony_ci	case DEV_STATE_BOXED:
2538c2ecf20Sopenharmony_ci		if (cdev->id.cu_type != 0) { /* device was recognized before */
2548c2ecf20Sopenharmony_ci			cdev->private->flags.recog_done = 1;
2558c2ecf20Sopenharmony_ci			cdev->private->state = DEV_STATE_BOXED;
2568c2ecf20Sopenharmony_ci			wake_up(&cdev->private->wait_q);
2578c2ecf20Sopenharmony_ci			return;
2588c2ecf20Sopenharmony_ci		}
2598c2ecf20Sopenharmony_ci		break;
2608c2ecf20Sopenharmony_ci	}
2618c2ecf20Sopenharmony_ci	cdev->private->state = state;
2628c2ecf20Sopenharmony_ci	io_subchannel_recog_done(cdev);
2638c2ecf20Sopenharmony_ci	wake_up(&cdev->private->wait_q);
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_ci/*
2678c2ecf20Sopenharmony_ci * Function called from device_id.c after sense id has completed.
2688c2ecf20Sopenharmony_ci */
2698c2ecf20Sopenharmony_civoid
2708c2ecf20Sopenharmony_ciccw_device_sense_id_done(struct ccw_device *cdev, int err)
2718c2ecf20Sopenharmony_ci{
2728c2ecf20Sopenharmony_ci	switch (err) {
2738c2ecf20Sopenharmony_ci	case 0:
2748c2ecf20Sopenharmony_ci		ccw_device_recog_done(cdev, DEV_STATE_OFFLINE);
2758c2ecf20Sopenharmony_ci		break;
2768c2ecf20Sopenharmony_ci	case -ETIME:		/* Sense id stopped by timeout. */
2778c2ecf20Sopenharmony_ci		ccw_device_recog_done(cdev, DEV_STATE_BOXED);
2788c2ecf20Sopenharmony_ci		break;
2798c2ecf20Sopenharmony_ci	default:
2808c2ecf20Sopenharmony_ci		ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
2818c2ecf20Sopenharmony_ci		break;
2828c2ecf20Sopenharmony_ci	}
2838c2ecf20Sopenharmony_ci}
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/**
2868c2ecf20Sopenharmony_ci  * ccw_device_notify() - inform the device's driver about an event
2878c2ecf20Sopenharmony_ci  * @cdev: device for which an event occurred
2888c2ecf20Sopenharmony_ci  * @event: event that occurred
2898c2ecf20Sopenharmony_ci  *
2908c2ecf20Sopenharmony_ci  * Returns:
2918c2ecf20Sopenharmony_ci  *   -%EINVAL if the device is offline or has no driver.
2928c2ecf20Sopenharmony_ci  *   -%EOPNOTSUPP if the device's driver has no notifier registered.
2938c2ecf20Sopenharmony_ci  *   %NOTIFY_OK if the driver wants to keep the device.
2948c2ecf20Sopenharmony_ci  *   %NOTIFY_BAD if the driver doesn't want to keep the device.
2958c2ecf20Sopenharmony_ci  */
2968c2ecf20Sopenharmony_ciint ccw_device_notify(struct ccw_device *cdev, int event)
2978c2ecf20Sopenharmony_ci{
2988c2ecf20Sopenharmony_ci	int ret = -EINVAL;
2998c2ecf20Sopenharmony_ci
3008c2ecf20Sopenharmony_ci	if (!cdev->drv)
3018c2ecf20Sopenharmony_ci		goto out;
3028c2ecf20Sopenharmony_ci	if (!cdev->online)
3038c2ecf20Sopenharmony_ci		goto out;
3048c2ecf20Sopenharmony_ci	CIO_MSG_EVENT(2, "notify called for 0.%x.%04x, event=%d\n",
3058c2ecf20Sopenharmony_ci		      cdev->private->dev_id.ssid, cdev->private->dev_id.devno,
3068c2ecf20Sopenharmony_ci		      event);
3078c2ecf20Sopenharmony_ci	if (!cdev->drv->notify) {
3088c2ecf20Sopenharmony_ci		ret = -EOPNOTSUPP;
3098c2ecf20Sopenharmony_ci		goto out;
3108c2ecf20Sopenharmony_ci	}
3118c2ecf20Sopenharmony_ci	if (cdev->drv->notify(cdev, event))
3128c2ecf20Sopenharmony_ci		ret = NOTIFY_OK;
3138c2ecf20Sopenharmony_ci	else
3148c2ecf20Sopenharmony_ci		ret = NOTIFY_BAD;
3158c2ecf20Sopenharmony_ciout:
3168c2ecf20Sopenharmony_ci	return ret;
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic void ccw_device_oper_notify(struct ccw_device *cdev)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	if (ccw_device_notify(cdev, CIO_OPER) == NOTIFY_OK) {
3248c2ecf20Sopenharmony_ci		/* Reenable channel measurements, if needed. */
3258c2ecf20Sopenharmony_ci		ccw_device_sched_todo(cdev, CDEV_TODO_ENABLE_CMF);
3268c2ecf20Sopenharmony_ci		/* Save indication for new paths. */
3278c2ecf20Sopenharmony_ci		cdev->private->path_new_mask = sch->vpm;
3288c2ecf20Sopenharmony_ci		return;
3298c2ecf20Sopenharmony_ci	}
3308c2ecf20Sopenharmony_ci	/* Driver doesn't want device back. */
3318c2ecf20Sopenharmony_ci	ccw_device_set_notoper(cdev);
3328c2ecf20Sopenharmony_ci	ccw_device_sched_todo(cdev, CDEV_TODO_REBIND);
3338c2ecf20Sopenharmony_ci}
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci/*
3368c2ecf20Sopenharmony_ci * Finished with online/offline processing.
3378c2ecf20Sopenharmony_ci */
3388c2ecf20Sopenharmony_cistatic void
3398c2ecf20Sopenharmony_ciccw_device_done(struct ccw_device *cdev, int state)
3408c2ecf20Sopenharmony_ci{
3418c2ecf20Sopenharmony_ci	struct subchannel *sch;
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci	ccw_device_set_timeout(cdev, 0);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	if (state != DEV_STATE_ONLINE)
3488c2ecf20Sopenharmony_ci		cio_disable_subchannel(sch);
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci	/* Reset device status. */
3518c2ecf20Sopenharmony_ci	memset(&cdev->private->dma_area->irb, 0, sizeof(struct irb));
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	cdev->private->state = state;
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	switch (state) {
3568c2ecf20Sopenharmony_ci	case DEV_STATE_BOXED:
3578c2ecf20Sopenharmony_ci		CIO_MSG_EVENT(0, "Boxed device %04x on subchannel %04x\n",
3588c2ecf20Sopenharmony_ci			      cdev->private->dev_id.devno, sch->schid.sch_no);
3598c2ecf20Sopenharmony_ci		if (cdev->online &&
3608c2ecf20Sopenharmony_ci		    ccw_device_notify(cdev, CIO_BOXED) != NOTIFY_OK)
3618c2ecf20Sopenharmony_ci			ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
3628c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
3638c2ecf20Sopenharmony_ci		break;
3648c2ecf20Sopenharmony_ci	case DEV_STATE_NOT_OPER:
3658c2ecf20Sopenharmony_ci		CIO_MSG_EVENT(0, "Device %04x gone on subchannel %04x\n",
3668c2ecf20Sopenharmony_ci			      cdev->private->dev_id.devno, sch->schid.sch_no);
3678c2ecf20Sopenharmony_ci		if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
3688c2ecf20Sopenharmony_ci			ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
3698c2ecf20Sopenharmony_ci		else
3708c2ecf20Sopenharmony_ci			ccw_device_set_disconnected(cdev);
3718c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
3728c2ecf20Sopenharmony_ci		break;
3738c2ecf20Sopenharmony_ci	case DEV_STATE_DISCONNECTED:
3748c2ecf20Sopenharmony_ci		CIO_MSG_EVENT(0, "Disconnected device %04x on subchannel "
3758c2ecf20Sopenharmony_ci			      "%04x\n", cdev->private->dev_id.devno,
3768c2ecf20Sopenharmony_ci			      sch->schid.sch_no);
3778c2ecf20Sopenharmony_ci		if (ccw_device_notify(cdev, CIO_NO_PATH) != NOTIFY_OK) {
3788c2ecf20Sopenharmony_ci			cdev->private->state = DEV_STATE_NOT_OPER;
3798c2ecf20Sopenharmony_ci			ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
3808c2ecf20Sopenharmony_ci		} else
3818c2ecf20Sopenharmony_ci			ccw_device_set_disconnected(cdev);
3828c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
3838c2ecf20Sopenharmony_ci		break;
3848c2ecf20Sopenharmony_ci	default:
3858c2ecf20Sopenharmony_ci		break;
3868c2ecf20Sopenharmony_ci	}
3878c2ecf20Sopenharmony_ci
3888c2ecf20Sopenharmony_ci	if (cdev->private->flags.donotify) {
3898c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
3908c2ecf20Sopenharmony_ci		ccw_device_oper_notify(cdev);
3918c2ecf20Sopenharmony_ci	}
3928c2ecf20Sopenharmony_ci	wake_up(&cdev->private->wait_q);
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/*
3968c2ecf20Sopenharmony_ci * Start device recognition.
3978c2ecf20Sopenharmony_ci */
3988c2ecf20Sopenharmony_civoid ccw_device_recognition(struct ccw_device *cdev)
3998c2ecf20Sopenharmony_ci{
4008c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	/*
4038c2ecf20Sopenharmony_ci	 * We used to start here with a sense pgid to find out whether a device
4048c2ecf20Sopenharmony_ci	 * is locked by someone else. Unfortunately, the sense pgid command
4058c2ecf20Sopenharmony_ci	 * code has other meanings on devices predating the path grouping
4068c2ecf20Sopenharmony_ci	 * algorithm, so we start with sense id and box the device after an
4078c2ecf20Sopenharmony_ci	 * timeout (or if sense pgid during path verification detects the device
4088c2ecf20Sopenharmony_ci	 * is locked, as may happen on newer devices).
4098c2ecf20Sopenharmony_ci	 */
4108c2ecf20Sopenharmony_ci	cdev->private->flags.recog_done = 0;
4118c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_SENSE_ID;
4128c2ecf20Sopenharmony_ci	if (cio_enable_subchannel(sch, (u32) (addr_t) sch)) {
4138c2ecf20Sopenharmony_ci		ccw_device_recog_done(cdev, DEV_STATE_NOT_OPER);
4148c2ecf20Sopenharmony_ci		return;
4158c2ecf20Sopenharmony_ci	}
4168c2ecf20Sopenharmony_ci	ccw_device_sense_id_start(cdev);
4178c2ecf20Sopenharmony_ci}
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci/*
4208c2ecf20Sopenharmony_ci * Handle events for states that use the ccw request infrastructure.
4218c2ecf20Sopenharmony_ci */
4228c2ecf20Sopenharmony_cistatic void ccw_device_request_event(struct ccw_device *cdev, enum dev_event e)
4238c2ecf20Sopenharmony_ci{
4248c2ecf20Sopenharmony_ci	switch (e) {
4258c2ecf20Sopenharmony_ci	case DEV_EVENT_NOTOPER:
4268c2ecf20Sopenharmony_ci		ccw_request_notoper(cdev);
4278c2ecf20Sopenharmony_ci		break;
4288c2ecf20Sopenharmony_ci	case DEV_EVENT_INTERRUPT:
4298c2ecf20Sopenharmony_ci		ccw_request_handler(cdev);
4308c2ecf20Sopenharmony_ci		break;
4318c2ecf20Sopenharmony_ci	case DEV_EVENT_TIMEOUT:
4328c2ecf20Sopenharmony_ci		ccw_request_timeout(cdev);
4338c2ecf20Sopenharmony_ci		break;
4348c2ecf20Sopenharmony_ci	default:
4358c2ecf20Sopenharmony_ci		break;
4368c2ecf20Sopenharmony_ci	}
4378c2ecf20Sopenharmony_ci}
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_cistatic void ccw_device_report_path_events(struct ccw_device *cdev)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
4428c2ecf20Sopenharmony_ci	int path_event[8];
4438c2ecf20Sopenharmony_ci	int chp, mask;
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	for (chp = 0, mask = 0x80; chp < 8; chp++, mask >>= 1) {
4468c2ecf20Sopenharmony_ci		path_event[chp] = PE_NONE;
4478c2ecf20Sopenharmony_ci		if (mask & cdev->private->path_gone_mask & ~(sch->vpm))
4488c2ecf20Sopenharmony_ci			path_event[chp] |= PE_PATH_GONE;
4498c2ecf20Sopenharmony_ci		if (mask & cdev->private->path_new_mask & sch->vpm)
4508c2ecf20Sopenharmony_ci			path_event[chp] |= PE_PATH_AVAILABLE;
4518c2ecf20Sopenharmony_ci		if (mask & cdev->private->pgid_reset_mask & sch->vpm)
4528c2ecf20Sopenharmony_ci			path_event[chp] |= PE_PATHGROUP_ESTABLISHED;
4538c2ecf20Sopenharmony_ci	}
4548c2ecf20Sopenharmony_ci	if (cdev->online && cdev->drv->path_event)
4558c2ecf20Sopenharmony_ci		cdev->drv->path_event(cdev, path_event);
4568c2ecf20Sopenharmony_ci}
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_cistatic void ccw_device_reset_path_events(struct ccw_device *cdev)
4598c2ecf20Sopenharmony_ci{
4608c2ecf20Sopenharmony_ci	cdev->private->path_gone_mask = 0;
4618c2ecf20Sopenharmony_ci	cdev->private->path_new_mask = 0;
4628c2ecf20Sopenharmony_ci	cdev->private->pgid_reset_mask = 0;
4638c2ecf20Sopenharmony_ci}
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistatic void create_fake_irb(struct irb *irb, int type)
4668c2ecf20Sopenharmony_ci{
4678c2ecf20Sopenharmony_ci	memset(irb, 0, sizeof(*irb));
4688c2ecf20Sopenharmony_ci	if (type == FAKE_CMD_IRB) {
4698c2ecf20Sopenharmony_ci		struct cmd_scsw *scsw = &irb->scsw.cmd;
4708c2ecf20Sopenharmony_ci		scsw->cc = 1;
4718c2ecf20Sopenharmony_ci		scsw->fctl = SCSW_FCTL_START_FUNC;
4728c2ecf20Sopenharmony_ci		scsw->actl = SCSW_ACTL_START_PEND;
4738c2ecf20Sopenharmony_ci		scsw->stctl = SCSW_STCTL_STATUS_PEND;
4748c2ecf20Sopenharmony_ci	} else if (type == FAKE_TM_IRB) {
4758c2ecf20Sopenharmony_ci		struct tm_scsw *scsw = &irb->scsw.tm;
4768c2ecf20Sopenharmony_ci		scsw->x = 1;
4778c2ecf20Sopenharmony_ci		scsw->cc = 1;
4788c2ecf20Sopenharmony_ci		scsw->fctl = SCSW_FCTL_START_FUNC;
4798c2ecf20Sopenharmony_ci		scsw->actl = SCSW_ACTL_START_PEND;
4808c2ecf20Sopenharmony_ci		scsw->stctl = SCSW_STCTL_STATUS_PEND;
4818c2ecf20Sopenharmony_ci	}
4828c2ecf20Sopenharmony_ci}
4838c2ecf20Sopenharmony_ci
4848c2ecf20Sopenharmony_cistatic void ccw_device_handle_broken_paths(struct ccw_device *cdev)
4858c2ecf20Sopenharmony_ci{
4868c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
4878c2ecf20Sopenharmony_ci	u8 broken_paths = (sch->schib.pmcw.pam & sch->opm) ^ sch->vpm;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	if (broken_paths && (cdev->private->path_broken_mask != broken_paths))
4908c2ecf20Sopenharmony_ci		ccw_device_schedule_recovery();
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	cdev->private->path_broken_mask = broken_paths;
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_civoid ccw_device_verify_done(struct ccw_device *cdev, int err)
4968c2ecf20Sopenharmony_ci{
4978c2ecf20Sopenharmony_ci	struct subchannel *sch;
4988c2ecf20Sopenharmony_ci
4998c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
5008c2ecf20Sopenharmony_ci	/* Update schib - pom may have changed. */
5018c2ecf20Sopenharmony_ci	if (cio_update_schib(sch)) {
5028c2ecf20Sopenharmony_ci		err = -ENODEV;
5038c2ecf20Sopenharmony_ci		goto callback;
5048c2ecf20Sopenharmony_ci	}
5058c2ecf20Sopenharmony_ci	/* Update lpm with verified path mask. */
5068c2ecf20Sopenharmony_ci	sch->lpm = sch->vpm;
5078c2ecf20Sopenharmony_ci	/* Repeat path verification? */
5088c2ecf20Sopenharmony_ci	if (cdev->private->flags.doverify) {
5098c2ecf20Sopenharmony_ci		ccw_device_verify_start(cdev);
5108c2ecf20Sopenharmony_ci		return;
5118c2ecf20Sopenharmony_ci	}
5128c2ecf20Sopenharmony_cicallback:
5138c2ecf20Sopenharmony_ci	switch (err) {
5148c2ecf20Sopenharmony_ci	case 0:
5158c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_ONLINE);
5168c2ecf20Sopenharmony_ci		/* Deliver fake irb to device driver, if needed. */
5178c2ecf20Sopenharmony_ci		if (cdev->private->flags.fake_irb) {
5188c2ecf20Sopenharmony_ci			create_fake_irb(&cdev->private->dma_area->irb,
5198c2ecf20Sopenharmony_ci					cdev->private->flags.fake_irb);
5208c2ecf20Sopenharmony_ci			cdev->private->flags.fake_irb = 0;
5218c2ecf20Sopenharmony_ci			if (cdev->handler)
5228c2ecf20Sopenharmony_ci				cdev->handler(cdev, cdev->private->intparm,
5238c2ecf20Sopenharmony_ci					      &cdev->private->dma_area->irb);
5248c2ecf20Sopenharmony_ci			memset(&cdev->private->dma_area->irb, 0,
5258c2ecf20Sopenharmony_ci			       sizeof(struct irb));
5268c2ecf20Sopenharmony_ci		}
5278c2ecf20Sopenharmony_ci		ccw_device_report_path_events(cdev);
5288c2ecf20Sopenharmony_ci		ccw_device_handle_broken_paths(cdev);
5298c2ecf20Sopenharmony_ci		break;
5308c2ecf20Sopenharmony_ci	case -ETIME:
5318c2ecf20Sopenharmony_ci	case -EUSERS:
5328c2ecf20Sopenharmony_ci		/* Reset oper notify indication after verify error. */
5338c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
5348c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_BOXED);
5358c2ecf20Sopenharmony_ci		break;
5368c2ecf20Sopenharmony_ci	case -EACCES:
5378c2ecf20Sopenharmony_ci		/* Reset oper notify indication after verify error. */
5388c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
5398c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_DISCONNECTED);
5408c2ecf20Sopenharmony_ci		break;
5418c2ecf20Sopenharmony_ci	default:
5428c2ecf20Sopenharmony_ci		/* Reset oper notify indication after verify error. */
5438c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
5448c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_NOT_OPER);
5458c2ecf20Sopenharmony_ci		break;
5468c2ecf20Sopenharmony_ci	}
5478c2ecf20Sopenharmony_ci	ccw_device_reset_path_events(cdev);
5488c2ecf20Sopenharmony_ci}
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/*
5518c2ecf20Sopenharmony_ci * Get device online.
5528c2ecf20Sopenharmony_ci */
5538c2ecf20Sopenharmony_ciint
5548c2ecf20Sopenharmony_ciccw_device_online(struct ccw_device *cdev)
5558c2ecf20Sopenharmony_ci{
5568c2ecf20Sopenharmony_ci	struct subchannel *sch;
5578c2ecf20Sopenharmony_ci	int ret;
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci	if ((cdev->private->state != DEV_STATE_OFFLINE) &&
5608c2ecf20Sopenharmony_ci	    (cdev->private->state != DEV_STATE_BOXED))
5618c2ecf20Sopenharmony_ci		return -EINVAL;
5628c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
5638c2ecf20Sopenharmony_ci	ret = cio_enable_subchannel(sch, (u32)(addr_t)sch);
5648c2ecf20Sopenharmony_ci	if (ret != 0) {
5658c2ecf20Sopenharmony_ci		/* Couldn't enable the subchannel for i/o. Sick device. */
5668c2ecf20Sopenharmony_ci		if (ret == -ENODEV)
5678c2ecf20Sopenharmony_ci			dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
5688c2ecf20Sopenharmony_ci		return ret;
5698c2ecf20Sopenharmony_ci	}
5708c2ecf20Sopenharmony_ci	/* Start initial path verification. */
5718c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_VERIFY;
5728c2ecf20Sopenharmony_ci	ccw_device_verify_start(cdev);
5738c2ecf20Sopenharmony_ci	return 0;
5748c2ecf20Sopenharmony_ci}
5758c2ecf20Sopenharmony_ci
5768c2ecf20Sopenharmony_civoid
5778c2ecf20Sopenharmony_ciccw_device_disband_done(struct ccw_device *cdev, int err)
5788c2ecf20Sopenharmony_ci{
5798c2ecf20Sopenharmony_ci	switch (err) {
5808c2ecf20Sopenharmony_ci	case 0:
5818c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_OFFLINE);
5828c2ecf20Sopenharmony_ci		break;
5838c2ecf20Sopenharmony_ci	case -ETIME:
5848c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_BOXED);
5858c2ecf20Sopenharmony_ci		break;
5868c2ecf20Sopenharmony_ci	default:
5878c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
5888c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_NOT_OPER);
5898c2ecf20Sopenharmony_ci		break;
5908c2ecf20Sopenharmony_ci	}
5918c2ecf20Sopenharmony_ci}
5928c2ecf20Sopenharmony_ci
5938c2ecf20Sopenharmony_ci/*
5948c2ecf20Sopenharmony_ci * Shutdown device.
5958c2ecf20Sopenharmony_ci */
5968c2ecf20Sopenharmony_ciint
5978c2ecf20Sopenharmony_ciccw_device_offline(struct ccw_device *cdev)
5988c2ecf20Sopenharmony_ci{
5998c2ecf20Sopenharmony_ci	struct subchannel *sch;
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	/* Allow ccw_device_offline while disconnected. */
6028c2ecf20Sopenharmony_ci	if (cdev->private->state == DEV_STATE_DISCONNECTED ||
6038c2ecf20Sopenharmony_ci	    cdev->private->state == DEV_STATE_NOT_OPER) {
6048c2ecf20Sopenharmony_ci		cdev->private->flags.donotify = 0;
6058c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_NOT_OPER);
6068c2ecf20Sopenharmony_ci		return 0;
6078c2ecf20Sopenharmony_ci	}
6088c2ecf20Sopenharmony_ci	if (cdev->private->state == DEV_STATE_BOXED) {
6098c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_BOXED);
6108c2ecf20Sopenharmony_ci		return 0;
6118c2ecf20Sopenharmony_ci	}
6128c2ecf20Sopenharmony_ci	if (ccw_device_is_orphan(cdev)) {
6138c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_OFFLINE);
6148c2ecf20Sopenharmony_ci		return 0;
6158c2ecf20Sopenharmony_ci	}
6168c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
6178c2ecf20Sopenharmony_ci	if (cio_update_schib(sch))
6188c2ecf20Sopenharmony_ci		return -ENODEV;
6198c2ecf20Sopenharmony_ci	if (scsw_actl(&sch->schib.scsw) != 0)
6208c2ecf20Sopenharmony_ci		return -EBUSY;
6218c2ecf20Sopenharmony_ci	if (cdev->private->state != DEV_STATE_ONLINE)
6228c2ecf20Sopenharmony_ci		return -EINVAL;
6238c2ecf20Sopenharmony_ci	/* Are we doing path grouping? */
6248c2ecf20Sopenharmony_ci	if (!cdev->private->flags.pgroup) {
6258c2ecf20Sopenharmony_ci		/* No, set state offline immediately. */
6268c2ecf20Sopenharmony_ci		ccw_device_done(cdev, DEV_STATE_OFFLINE);
6278c2ecf20Sopenharmony_ci		return 0;
6288c2ecf20Sopenharmony_ci	}
6298c2ecf20Sopenharmony_ci	/* Start Set Path Group commands. */
6308c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_DISBAND_PGID;
6318c2ecf20Sopenharmony_ci	ccw_device_disband_start(cdev);
6328c2ecf20Sopenharmony_ci	return 0;
6338c2ecf20Sopenharmony_ci}
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci/*
6368c2ecf20Sopenharmony_ci * Handle not operational event in non-special state.
6378c2ecf20Sopenharmony_ci */
6388c2ecf20Sopenharmony_cistatic void ccw_device_generic_notoper(struct ccw_device *cdev,
6398c2ecf20Sopenharmony_ci				       enum dev_event dev_event)
6408c2ecf20Sopenharmony_ci{
6418c2ecf20Sopenharmony_ci	if (ccw_device_notify(cdev, CIO_GONE) != NOTIFY_OK)
6428c2ecf20Sopenharmony_ci		ccw_device_sched_todo(cdev, CDEV_TODO_UNREG);
6438c2ecf20Sopenharmony_ci	else
6448c2ecf20Sopenharmony_ci		ccw_device_set_disconnected(cdev);
6458c2ecf20Sopenharmony_ci}
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci/*
6488c2ecf20Sopenharmony_ci * Handle path verification event in offline state.
6498c2ecf20Sopenharmony_ci */
6508c2ecf20Sopenharmony_cistatic void ccw_device_offline_verify(struct ccw_device *cdev,
6518c2ecf20Sopenharmony_ci				      enum dev_event dev_event)
6528c2ecf20Sopenharmony_ci{
6538c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
6548c2ecf20Sopenharmony_ci
6558c2ecf20Sopenharmony_ci	css_schedule_eval(sch->schid);
6568c2ecf20Sopenharmony_ci}
6578c2ecf20Sopenharmony_ci
6588c2ecf20Sopenharmony_ci/*
6598c2ecf20Sopenharmony_ci * Handle path verification event.
6608c2ecf20Sopenharmony_ci */
6618c2ecf20Sopenharmony_cistatic void
6628c2ecf20Sopenharmony_ciccw_device_online_verify(struct ccw_device *cdev, enum dev_event dev_event)
6638c2ecf20Sopenharmony_ci{
6648c2ecf20Sopenharmony_ci	struct subchannel *sch;
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ci	if (cdev->private->state == DEV_STATE_W4SENSE) {
6678c2ecf20Sopenharmony_ci		cdev->private->flags.doverify = 1;
6688c2ecf20Sopenharmony_ci		return;
6698c2ecf20Sopenharmony_ci	}
6708c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
6718c2ecf20Sopenharmony_ci	/*
6728c2ecf20Sopenharmony_ci	 * Since we might not just be coming from an interrupt from the
6738c2ecf20Sopenharmony_ci	 * subchannel we have to update the schib.
6748c2ecf20Sopenharmony_ci	 */
6758c2ecf20Sopenharmony_ci	if (cio_update_schib(sch)) {
6768c2ecf20Sopenharmony_ci		ccw_device_verify_done(cdev, -ENODEV);
6778c2ecf20Sopenharmony_ci		return;
6788c2ecf20Sopenharmony_ci	}
6798c2ecf20Sopenharmony_ci
6808c2ecf20Sopenharmony_ci	if (scsw_actl(&sch->schib.scsw) != 0 ||
6818c2ecf20Sopenharmony_ci	    (scsw_stctl(&sch->schib.scsw) & SCSW_STCTL_STATUS_PEND) ||
6828c2ecf20Sopenharmony_ci	    (scsw_stctl(&cdev->private->dma_area->irb.scsw) &
6838c2ecf20Sopenharmony_ci	     SCSW_STCTL_STATUS_PEND)) {
6848c2ecf20Sopenharmony_ci		/*
6858c2ecf20Sopenharmony_ci		 * No final status yet or final status not yet delivered
6868c2ecf20Sopenharmony_ci		 * to the device driver. Can't do path verification now,
6878c2ecf20Sopenharmony_ci		 * delay until final status was delivered.
6888c2ecf20Sopenharmony_ci		 */
6898c2ecf20Sopenharmony_ci		cdev->private->flags.doverify = 1;
6908c2ecf20Sopenharmony_ci		return;
6918c2ecf20Sopenharmony_ci	}
6928c2ecf20Sopenharmony_ci	/* Device is idle, we can do the path verification. */
6938c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_VERIFY;
6948c2ecf20Sopenharmony_ci	ccw_device_verify_start(cdev);
6958c2ecf20Sopenharmony_ci}
6968c2ecf20Sopenharmony_ci
6978c2ecf20Sopenharmony_ci/*
6988c2ecf20Sopenharmony_ci * Handle path verification event in boxed state.
6998c2ecf20Sopenharmony_ci */
7008c2ecf20Sopenharmony_cistatic void ccw_device_boxed_verify(struct ccw_device *cdev,
7018c2ecf20Sopenharmony_ci				    enum dev_event dev_event)
7028c2ecf20Sopenharmony_ci{
7038c2ecf20Sopenharmony_ci	struct subchannel *sch = to_subchannel(cdev->dev.parent);
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_ci	if (cdev->online) {
7068c2ecf20Sopenharmony_ci		if (cio_enable_subchannel(sch, (u32) (addr_t) sch))
7078c2ecf20Sopenharmony_ci			ccw_device_done(cdev, DEV_STATE_NOT_OPER);
7088c2ecf20Sopenharmony_ci		else
7098c2ecf20Sopenharmony_ci			ccw_device_online_verify(cdev, dev_event);
7108c2ecf20Sopenharmony_ci	} else
7118c2ecf20Sopenharmony_ci		css_schedule_eval(sch->schid);
7128c2ecf20Sopenharmony_ci}
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci/*
7158c2ecf20Sopenharmony_ci * Pass interrupt to device driver.
7168c2ecf20Sopenharmony_ci */
7178c2ecf20Sopenharmony_cistatic int ccw_device_call_handler(struct ccw_device *cdev)
7188c2ecf20Sopenharmony_ci{
7198c2ecf20Sopenharmony_ci	unsigned int stctl;
7208c2ecf20Sopenharmony_ci	int ending_status;
7218c2ecf20Sopenharmony_ci
7228c2ecf20Sopenharmony_ci	/*
7238c2ecf20Sopenharmony_ci	 * we allow for the device action handler if .
7248c2ecf20Sopenharmony_ci	 *  - we received ending status
7258c2ecf20Sopenharmony_ci	 *  - the action handler requested to see all interrupts
7268c2ecf20Sopenharmony_ci	 *  - we received an intermediate status
7278c2ecf20Sopenharmony_ci	 *  - fast notification was requested (primary status)
7288c2ecf20Sopenharmony_ci	 *  - unsolicited interrupts
7298c2ecf20Sopenharmony_ci	 */
7308c2ecf20Sopenharmony_ci	stctl = scsw_stctl(&cdev->private->dma_area->irb.scsw);
7318c2ecf20Sopenharmony_ci	ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||
7328c2ecf20Sopenharmony_ci		(stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||
7338c2ecf20Sopenharmony_ci		(stctl == SCSW_STCTL_STATUS_PEND);
7348c2ecf20Sopenharmony_ci	if (!ending_status &&
7358c2ecf20Sopenharmony_ci	    !cdev->private->options.repall &&
7368c2ecf20Sopenharmony_ci	    !(stctl & SCSW_STCTL_INTER_STATUS) &&
7378c2ecf20Sopenharmony_ci	    !(cdev->private->options.fast &&
7388c2ecf20Sopenharmony_ci	      (stctl & SCSW_STCTL_PRIM_STATUS)))
7398c2ecf20Sopenharmony_ci		return 0;
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_ci	if (ending_status)
7428c2ecf20Sopenharmony_ci		ccw_device_set_timeout(cdev, 0);
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci	if (cdev->handler)
7458c2ecf20Sopenharmony_ci		cdev->handler(cdev, cdev->private->intparm,
7468c2ecf20Sopenharmony_ci			      &cdev->private->dma_area->irb);
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	memset(&cdev->private->dma_area->irb, 0, sizeof(struct irb));
7498c2ecf20Sopenharmony_ci	return 1;
7508c2ecf20Sopenharmony_ci}
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci/*
7538c2ecf20Sopenharmony_ci * Got an interrupt for a normal io (state online).
7548c2ecf20Sopenharmony_ci */
7558c2ecf20Sopenharmony_cistatic void
7568c2ecf20Sopenharmony_ciccw_device_irq(struct ccw_device *cdev, enum dev_event dev_event)
7578c2ecf20Sopenharmony_ci{
7588c2ecf20Sopenharmony_ci	struct irb *irb;
7598c2ecf20Sopenharmony_ci	int is_cmd;
7608c2ecf20Sopenharmony_ci
7618c2ecf20Sopenharmony_ci	irb = this_cpu_ptr(&cio_irb);
7628c2ecf20Sopenharmony_ci	is_cmd = !scsw_is_tm(&irb->scsw);
7638c2ecf20Sopenharmony_ci	/* Check for unsolicited interrupt. */
7648c2ecf20Sopenharmony_ci	if (!scsw_is_solicited(&irb->scsw)) {
7658c2ecf20Sopenharmony_ci		if (is_cmd && (irb->scsw.cmd.dstat & DEV_STAT_UNIT_CHECK) &&
7668c2ecf20Sopenharmony_ci		    !irb->esw.esw0.erw.cons) {
7678c2ecf20Sopenharmony_ci			/* Unit check but no sense data. Need basic sense. */
7688c2ecf20Sopenharmony_ci			if (ccw_device_do_sense(cdev, irb) != 0)
7698c2ecf20Sopenharmony_ci				goto call_handler_unsol;
7708c2ecf20Sopenharmony_ci			memcpy(&cdev->private->dma_area->irb, irb,
7718c2ecf20Sopenharmony_ci			       sizeof(struct irb));
7728c2ecf20Sopenharmony_ci			cdev->private->state = DEV_STATE_W4SENSE;
7738c2ecf20Sopenharmony_ci			cdev->private->intparm = 0;
7748c2ecf20Sopenharmony_ci			return;
7758c2ecf20Sopenharmony_ci		}
7768c2ecf20Sopenharmony_cicall_handler_unsol:
7778c2ecf20Sopenharmony_ci		if (cdev->handler)
7788c2ecf20Sopenharmony_ci			cdev->handler (cdev, 0, irb);
7798c2ecf20Sopenharmony_ci		if (cdev->private->flags.doverify)
7808c2ecf20Sopenharmony_ci			ccw_device_online_verify(cdev, 0);
7818c2ecf20Sopenharmony_ci		return;
7828c2ecf20Sopenharmony_ci	}
7838c2ecf20Sopenharmony_ci	/* Accumulate status and find out if a basic sense is needed. */
7848c2ecf20Sopenharmony_ci	ccw_device_accumulate_irb(cdev, irb);
7858c2ecf20Sopenharmony_ci	if (is_cmd && cdev->private->flags.dosense) {
7868c2ecf20Sopenharmony_ci		if (ccw_device_do_sense(cdev, irb) == 0) {
7878c2ecf20Sopenharmony_ci			cdev->private->state = DEV_STATE_W4SENSE;
7888c2ecf20Sopenharmony_ci		}
7898c2ecf20Sopenharmony_ci		return;
7908c2ecf20Sopenharmony_ci	}
7918c2ecf20Sopenharmony_ci	/* Call the handler. */
7928c2ecf20Sopenharmony_ci	if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
7938c2ecf20Sopenharmony_ci		/* Start delayed path verification. */
7948c2ecf20Sopenharmony_ci		ccw_device_online_verify(cdev, 0);
7958c2ecf20Sopenharmony_ci}
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci/*
7988c2ecf20Sopenharmony_ci * Got an timeout in online state.
7998c2ecf20Sopenharmony_ci */
8008c2ecf20Sopenharmony_cistatic void
8018c2ecf20Sopenharmony_ciccw_device_online_timeout(struct ccw_device *cdev, enum dev_event dev_event)
8028c2ecf20Sopenharmony_ci{
8038c2ecf20Sopenharmony_ci	int ret;
8048c2ecf20Sopenharmony_ci
8058c2ecf20Sopenharmony_ci	ccw_device_set_timeout(cdev, 0);
8068c2ecf20Sopenharmony_ci	cdev->private->iretry = 255;
8078c2ecf20Sopenharmony_ci	cdev->private->async_kill_io_rc = -ETIMEDOUT;
8088c2ecf20Sopenharmony_ci	ret = ccw_device_cancel_halt_clear(cdev);
8098c2ecf20Sopenharmony_ci	if (ret == -EBUSY) {
8108c2ecf20Sopenharmony_ci		ccw_device_set_timeout(cdev, 3*HZ);
8118c2ecf20Sopenharmony_ci		cdev->private->state = DEV_STATE_TIMEOUT_KILL;
8128c2ecf20Sopenharmony_ci		return;
8138c2ecf20Sopenharmony_ci	}
8148c2ecf20Sopenharmony_ci	if (ret)
8158c2ecf20Sopenharmony_ci		dev_fsm_event(cdev, DEV_EVENT_NOTOPER);
8168c2ecf20Sopenharmony_ci	else if (cdev->handler)
8178c2ecf20Sopenharmony_ci		cdev->handler(cdev, cdev->private->intparm,
8188c2ecf20Sopenharmony_ci			      ERR_PTR(-ETIMEDOUT));
8198c2ecf20Sopenharmony_ci}
8208c2ecf20Sopenharmony_ci
8218c2ecf20Sopenharmony_ci/*
8228c2ecf20Sopenharmony_ci * Got an interrupt for a basic sense.
8238c2ecf20Sopenharmony_ci */
8248c2ecf20Sopenharmony_cistatic void
8258c2ecf20Sopenharmony_ciccw_device_w4sense(struct ccw_device *cdev, enum dev_event dev_event)
8268c2ecf20Sopenharmony_ci{
8278c2ecf20Sopenharmony_ci	struct irb *irb;
8288c2ecf20Sopenharmony_ci
8298c2ecf20Sopenharmony_ci	irb = this_cpu_ptr(&cio_irb);
8308c2ecf20Sopenharmony_ci	/* Check for unsolicited interrupt. */
8318c2ecf20Sopenharmony_ci	if (scsw_stctl(&irb->scsw) ==
8328c2ecf20Sopenharmony_ci	    (SCSW_STCTL_STATUS_PEND | SCSW_STCTL_ALERT_STATUS)) {
8338c2ecf20Sopenharmony_ci		if (scsw_cc(&irb->scsw) == 1)
8348c2ecf20Sopenharmony_ci			/* Basic sense hasn't started. Try again. */
8358c2ecf20Sopenharmony_ci			ccw_device_do_sense(cdev, irb);
8368c2ecf20Sopenharmony_ci		else {
8378c2ecf20Sopenharmony_ci			CIO_MSG_EVENT(0, "0.%x.%04x: unsolicited "
8388c2ecf20Sopenharmony_ci				      "interrupt during w4sense...\n",
8398c2ecf20Sopenharmony_ci				      cdev->private->dev_id.ssid,
8408c2ecf20Sopenharmony_ci				      cdev->private->dev_id.devno);
8418c2ecf20Sopenharmony_ci			if (cdev->handler)
8428c2ecf20Sopenharmony_ci				cdev->handler (cdev, 0, irb);
8438c2ecf20Sopenharmony_ci		}
8448c2ecf20Sopenharmony_ci		return;
8458c2ecf20Sopenharmony_ci	}
8468c2ecf20Sopenharmony_ci	/*
8478c2ecf20Sopenharmony_ci	 * Check if a halt or clear has been issued in the meanwhile. If yes,
8488c2ecf20Sopenharmony_ci	 * only deliver the halt/clear interrupt to the device driver as if it
8498c2ecf20Sopenharmony_ci	 * had killed the original request.
8508c2ecf20Sopenharmony_ci	 */
8518c2ecf20Sopenharmony_ci	if (scsw_fctl(&irb->scsw) &
8528c2ecf20Sopenharmony_ci	    (SCSW_FCTL_CLEAR_FUNC | SCSW_FCTL_HALT_FUNC)) {
8538c2ecf20Sopenharmony_ci		cdev->private->flags.dosense = 0;
8548c2ecf20Sopenharmony_ci		memset(&cdev->private->dma_area->irb, 0, sizeof(struct irb));
8558c2ecf20Sopenharmony_ci		ccw_device_accumulate_irb(cdev, irb);
8568c2ecf20Sopenharmony_ci		goto call_handler;
8578c2ecf20Sopenharmony_ci	}
8588c2ecf20Sopenharmony_ci	/* Add basic sense info to irb. */
8598c2ecf20Sopenharmony_ci	ccw_device_accumulate_basic_sense(cdev, irb);
8608c2ecf20Sopenharmony_ci	if (cdev->private->flags.dosense) {
8618c2ecf20Sopenharmony_ci		/* Another basic sense is needed. */
8628c2ecf20Sopenharmony_ci		ccw_device_do_sense(cdev, irb);
8638c2ecf20Sopenharmony_ci		return;
8648c2ecf20Sopenharmony_ci	}
8658c2ecf20Sopenharmony_cicall_handler:
8668c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_ONLINE;
8678c2ecf20Sopenharmony_ci	/* In case sensing interfered with setting the device online */
8688c2ecf20Sopenharmony_ci	wake_up(&cdev->private->wait_q);
8698c2ecf20Sopenharmony_ci	/* Call the handler. */
8708c2ecf20Sopenharmony_ci	if (ccw_device_call_handler(cdev) && cdev->private->flags.doverify)
8718c2ecf20Sopenharmony_ci		/* Start delayed path verification. */
8728c2ecf20Sopenharmony_ci		ccw_device_online_verify(cdev, 0);
8738c2ecf20Sopenharmony_ci}
8748c2ecf20Sopenharmony_ci
8758c2ecf20Sopenharmony_cistatic void
8768c2ecf20Sopenharmony_ciccw_device_killing_irq(struct ccw_device *cdev, enum dev_event dev_event)
8778c2ecf20Sopenharmony_ci{
8788c2ecf20Sopenharmony_ci	ccw_device_set_timeout(cdev, 0);
8798c2ecf20Sopenharmony_ci	/* Start delayed path verification. */
8808c2ecf20Sopenharmony_ci	ccw_device_online_verify(cdev, 0);
8818c2ecf20Sopenharmony_ci	/* OK, i/o is dead now. Call interrupt handler. */
8828c2ecf20Sopenharmony_ci	if (cdev->handler)
8838c2ecf20Sopenharmony_ci		cdev->handler(cdev, cdev->private->intparm,
8848c2ecf20Sopenharmony_ci			      ERR_PTR(cdev->private->async_kill_io_rc));
8858c2ecf20Sopenharmony_ci}
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_cistatic void
8888c2ecf20Sopenharmony_ciccw_device_killing_timeout(struct ccw_device *cdev, enum dev_event dev_event)
8898c2ecf20Sopenharmony_ci{
8908c2ecf20Sopenharmony_ci	int ret;
8918c2ecf20Sopenharmony_ci
8928c2ecf20Sopenharmony_ci	ret = ccw_device_cancel_halt_clear(cdev);
8938c2ecf20Sopenharmony_ci	if (ret == -EBUSY) {
8948c2ecf20Sopenharmony_ci		ccw_device_set_timeout(cdev, 3*HZ);
8958c2ecf20Sopenharmony_ci		return;
8968c2ecf20Sopenharmony_ci	}
8978c2ecf20Sopenharmony_ci	/* Start delayed path verification. */
8988c2ecf20Sopenharmony_ci	ccw_device_online_verify(cdev, 0);
8998c2ecf20Sopenharmony_ci	if (cdev->handler)
9008c2ecf20Sopenharmony_ci		cdev->handler(cdev, cdev->private->intparm,
9018c2ecf20Sopenharmony_ci			      ERR_PTR(cdev->private->async_kill_io_rc));
9028c2ecf20Sopenharmony_ci}
9038c2ecf20Sopenharmony_ci
9048c2ecf20Sopenharmony_civoid ccw_device_kill_io(struct ccw_device *cdev)
9058c2ecf20Sopenharmony_ci{
9068c2ecf20Sopenharmony_ci	int ret;
9078c2ecf20Sopenharmony_ci
9088c2ecf20Sopenharmony_ci	ccw_device_set_timeout(cdev, 0);
9098c2ecf20Sopenharmony_ci	cdev->private->iretry = 255;
9108c2ecf20Sopenharmony_ci	cdev->private->async_kill_io_rc = -EIO;
9118c2ecf20Sopenharmony_ci	ret = ccw_device_cancel_halt_clear(cdev);
9128c2ecf20Sopenharmony_ci	if (ret == -EBUSY) {
9138c2ecf20Sopenharmony_ci		ccw_device_set_timeout(cdev, 3*HZ);
9148c2ecf20Sopenharmony_ci		cdev->private->state = DEV_STATE_TIMEOUT_KILL;
9158c2ecf20Sopenharmony_ci		return;
9168c2ecf20Sopenharmony_ci	}
9178c2ecf20Sopenharmony_ci	/* Start delayed path verification. */
9188c2ecf20Sopenharmony_ci	ccw_device_online_verify(cdev, 0);
9198c2ecf20Sopenharmony_ci	if (cdev->handler)
9208c2ecf20Sopenharmony_ci		cdev->handler(cdev, cdev->private->intparm,
9218c2ecf20Sopenharmony_ci			      ERR_PTR(-EIO));
9228c2ecf20Sopenharmony_ci}
9238c2ecf20Sopenharmony_ci
9248c2ecf20Sopenharmony_cistatic void
9258c2ecf20Sopenharmony_ciccw_device_delay_verify(struct ccw_device *cdev, enum dev_event dev_event)
9268c2ecf20Sopenharmony_ci{
9278c2ecf20Sopenharmony_ci	/* Start verification after current task finished. */
9288c2ecf20Sopenharmony_ci	cdev->private->flags.doverify = 1;
9298c2ecf20Sopenharmony_ci}
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_cistatic void
9328c2ecf20Sopenharmony_ciccw_device_start_id(struct ccw_device *cdev, enum dev_event dev_event)
9338c2ecf20Sopenharmony_ci{
9348c2ecf20Sopenharmony_ci	struct subchannel *sch;
9358c2ecf20Sopenharmony_ci
9368c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
9378c2ecf20Sopenharmony_ci	if (cio_enable_subchannel(sch, (u32)(addr_t)sch) != 0)
9388c2ecf20Sopenharmony_ci		/* Couldn't enable the subchannel for i/o. Sick device. */
9398c2ecf20Sopenharmony_ci		return;
9408c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_DISCONNECTED_SENSE_ID;
9418c2ecf20Sopenharmony_ci	ccw_device_sense_id_start(cdev);
9428c2ecf20Sopenharmony_ci}
9438c2ecf20Sopenharmony_ci
9448c2ecf20Sopenharmony_civoid ccw_device_trigger_reprobe(struct ccw_device *cdev)
9458c2ecf20Sopenharmony_ci{
9468c2ecf20Sopenharmony_ci	struct subchannel *sch;
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci	if (cdev->private->state != DEV_STATE_DISCONNECTED)
9498c2ecf20Sopenharmony_ci		return;
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
9528c2ecf20Sopenharmony_ci	/* Update some values. */
9538c2ecf20Sopenharmony_ci	if (cio_update_schib(sch))
9548c2ecf20Sopenharmony_ci		return;
9558c2ecf20Sopenharmony_ci	/*
9568c2ecf20Sopenharmony_ci	 * The pim, pam, pom values may not be accurate, but they are the best
9578c2ecf20Sopenharmony_ci	 * we have before performing device selection :/
9588c2ecf20Sopenharmony_ci	 */
9598c2ecf20Sopenharmony_ci	sch->lpm = sch->schib.pmcw.pam & sch->opm;
9608c2ecf20Sopenharmony_ci	/*
9618c2ecf20Sopenharmony_ci	 * Use the initial configuration since we can't be shure that the old
9628c2ecf20Sopenharmony_ci	 * paths are valid.
9638c2ecf20Sopenharmony_ci	 */
9648c2ecf20Sopenharmony_ci	io_subchannel_init_config(sch);
9658c2ecf20Sopenharmony_ci	if (cio_commit_config(sch))
9668c2ecf20Sopenharmony_ci		return;
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci	/* We should also udate ssd info, but this has to wait. */
9698c2ecf20Sopenharmony_ci	/* Check if this is another device which appeared on the same sch. */
9708c2ecf20Sopenharmony_ci	if (sch->schib.pmcw.dev != cdev->private->dev_id.devno)
9718c2ecf20Sopenharmony_ci		css_schedule_eval(sch->schid);
9728c2ecf20Sopenharmony_ci	else
9738c2ecf20Sopenharmony_ci		ccw_device_start_id(cdev, 0);
9748c2ecf20Sopenharmony_ci}
9758c2ecf20Sopenharmony_ci
9768c2ecf20Sopenharmony_cistatic void ccw_device_disabled_irq(struct ccw_device *cdev,
9778c2ecf20Sopenharmony_ci				    enum dev_event dev_event)
9788c2ecf20Sopenharmony_ci{
9798c2ecf20Sopenharmony_ci	struct subchannel *sch;
9808c2ecf20Sopenharmony_ci
9818c2ecf20Sopenharmony_ci	sch = to_subchannel(cdev->dev.parent);
9828c2ecf20Sopenharmony_ci	/*
9838c2ecf20Sopenharmony_ci	 * An interrupt in a disabled state means a previous disable was not
9848c2ecf20Sopenharmony_ci	 * successful - should not happen, but we try to disable again.
9858c2ecf20Sopenharmony_ci	 */
9868c2ecf20Sopenharmony_ci	cio_disable_subchannel(sch);
9878c2ecf20Sopenharmony_ci}
9888c2ecf20Sopenharmony_ci
9898c2ecf20Sopenharmony_cistatic void
9908c2ecf20Sopenharmony_ciccw_device_change_cmfstate(struct ccw_device *cdev, enum dev_event dev_event)
9918c2ecf20Sopenharmony_ci{
9928c2ecf20Sopenharmony_ci	retry_set_schib(cdev);
9938c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_ONLINE;
9948c2ecf20Sopenharmony_ci	dev_fsm_event(cdev, dev_event);
9958c2ecf20Sopenharmony_ci}
9968c2ecf20Sopenharmony_ci
9978c2ecf20Sopenharmony_cistatic void ccw_device_update_cmfblock(struct ccw_device *cdev,
9988c2ecf20Sopenharmony_ci				       enum dev_event dev_event)
9998c2ecf20Sopenharmony_ci{
10008c2ecf20Sopenharmony_ci	cmf_retry_copy_block(cdev);
10018c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_ONLINE;
10028c2ecf20Sopenharmony_ci	dev_fsm_event(cdev, dev_event);
10038c2ecf20Sopenharmony_ci}
10048c2ecf20Sopenharmony_ci
10058c2ecf20Sopenharmony_cistatic void
10068c2ecf20Sopenharmony_ciccw_device_quiesce_done(struct ccw_device *cdev, enum dev_event dev_event)
10078c2ecf20Sopenharmony_ci{
10088c2ecf20Sopenharmony_ci	ccw_device_set_timeout(cdev, 0);
10098c2ecf20Sopenharmony_ci	cdev->private->state = DEV_STATE_NOT_OPER;
10108c2ecf20Sopenharmony_ci	wake_up(&cdev->private->wait_q);
10118c2ecf20Sopenharmony_ci}
10128c2ecf20Sopenharmony_ci
10138c2ecf20Sopenharmony_cistatic void
10148c2ecf20Sopenharmony_ciccw_device_quiesce_timeout(struct ccw_device *cdev, enum dev_event dev_event)
10158c2ecf20Sopenharmony_ci{
10168c2ecf20Sopenharmony_ci	int ret;
10178c2ecf20Sopenharmony_ci
10188c2ecf20Sopenharmony_ci	ret = ccw_device_cancel_halt_clear(cdev);
10198c2ecf20Sopenharmony_ci	if (ret == -EBUSY) {
10208c2ecf20Sopenharmony_ci		ccw_device_set_timeout(cdev, HZ/10);
10218c2ecf20Sopenharmony_ci	} else {
10228c2ecf20Sopenharmony_ci		cdev->private->state = DEV_STATE_NOT_OPER;
10238c2ecf20Sopenharmony_ci		wake_up(&cdev->private->wait_q);
10248c2ecf20Sopenharmony_ci	}
10258c2ecf20Sopenharmony_ci}
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci/*
10288c2ecf20Sopenharmony_ci * No operation action. This is used e.g. to ignore a timeout event in
10298c2ecf20Sopenharmony_ci * state offline.
10308c2ecf20Sopenharmony_ci */
10318c2ecf20Sopenharmony_cistatic void
10328c2ecf20Sopenharmony_ciccw_device_nop(struct ccw_device *cdev, enum dev_event dev_event)
10338c2ecf20Sopenharmony_ci{
10348c2ecf20Sopenharmony_ci}
10358c2ecf20Sopenharmony_ci
10368c2ecf20Sopenharmony_ci/*
10378c2ecf20Sopenharmony_ci * device statemachine
10388c2ecf20Sopenharmony_ci */
10398c2ecf20Sopenharmony_cifsm_func_t *dev_jumptable[NR_DEV_STATES][NR_DEV_EVENTS] = {
10408c2ecf20Sopenharmony_ci	[DEV_STATE_NOT_OPER] = {
10418c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_nop,
10428c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_disabled_irq,
10438c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_nop,
10448c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
10458c2ecf20Sopenharmony_ci	},
10468c2ecf20Sopenharmony_ci	[DEV_STATE_SENSE_ID] = {
10478c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_request_event,
10488c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_request_event,
10498c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_request_event,
10508c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
10518c2ecf20Sopenharmony_ci	},
10528c2ecf20Sopenharmony_ci	[DEV_STATE_OFFLINE] = {
10538c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_generic_notoper,
10548c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_disabled_irq,
10558c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_nop,
10568c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_offline_verify,
10578c2ecf20Sopenharmony_ci	},
10588c2ecf20Sopenharmony_ci	[DEV_STATE_VERIFY] = {
10598c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_request_event,
10608c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_request_event,
10618c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_request_event,
10628c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_delay_verify,
10638c2ecf20Sopenharmony_ci	},
10648c2ecf20Sopenharmony_ci	[DEV_STATE_ONLINE] = {
10658c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_generic_notoper,
10668c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_irq,
10678c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_online_timeout,
10688c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_online_verify,
10698c2ecf20Sopenharmony_ci	},
10708c2ecf20Sopenharmony_ci	[DEV_STATE_W4SENSE] = {
10718c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_generic_notoper,
10728c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_w4sense,
10738c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_nop,
10748c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_online_verify,
10758c2ecf20Sopenharmony_ci	},
10768c2ecf20Sopenharmony_ci	[DEV_STATE_DISBAND_PGID] = {
10778c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_request_event,
10788c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_request_event,
10798c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_request_event,
10808c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
10818c2ecf20Sopenharmony_ci	},
10828c2ecf20Sopenharmony_ci	[DEV_STATE_BOXED] = {
10838c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_generic_notoper,
10848c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_nop,
10858c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_nop,
10868c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_boxed_verify,
10878c2ecf20Sopenharmony_ci	},
10888c2ecf20Sopenharmony_ci	/* states to wait for i/o completion before doing something */
10898c2ecf20Sopenharmony_ci	[DEV_STATE_TIMEOUT_KILL] = {
10908c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_generic_notoper,
10918c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_killing_irq,
10928c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_killing_timeout,
10938c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop, //FIXME
10948c2ecf20Sopenharmony_ci	},
10958c2ecf20Sopenharmony_ci	[DEV_STATE_QUIESCE] = {
10968c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_quiesce_done,
10978c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_quiesce_done,
10988c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_quiesce_timeout,
10998c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
11008c2ecf20Sopenharmony_ci	},
11018c2ecf20Sopenharmony_ci	/* special states for devices gone not operational */
11028c2ecf20Sopenharmony_ci	[DEV_STATE_DISCONNECTED] = {
11038c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_nop,
11048c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_start_id,
11058c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_nop,
11068c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_start_id,
11078c2ecf20Sopenharmony_ci	},
11088c2ecf20Sopenharmony_ci	[DEV_STATE_DISCONNECTED_SENSE_ID] = {
11098c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_request_event,
11108c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_request_event,
11118c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_request_event,
11128c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
11138c2ecf20Sopenharmony_ci	},
11148c2ecf20Sopenharmony_ci	[DEV_STATE_CMFCHANGE] = {
11158c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_change_cmfstate,
11168c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_change_cmfstate,
11178c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_change_cmfstate,
11188c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_change_cmfstate,
11198c2ecf20Sopenharmony_ci	},
11208c2ecf20Sopenharmony_ci	[DEV_STATE_CMFUPDATE] = {
11218c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_update_cmfblock,
11228c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_update_cmfblock,
11238c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_update_cmfblock,
11248c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_update_cmfblock,
11258c2ecf20Sopenharmony_ci	},
11268c2ecf20Sopenharmony_ci	[DEV_STATE_STEAL_LOCK] = {
11278c2ecf20Sopenharmony_ci		[DEV_EVENT_NOTOPER]	= ccw_device_request_event,
11288c2ecf20Sopenharmony_ci		[DEV_EVENT_INTERRUPT]	= ccw_device_request_event,
11298c2ecf20Sopenharmony_ci		[DEV_EVENT_TIMEOUT]	= ccw_device_request_event,
11308c2ecf20Sopenharmony_ci		[DEV_EVENT_VERIFY]	= ccw_device_nop,
11318c2ecf20Sopenharmony_ci	},
11328c2ecf20Sopenharmony_ci};
11338c2ecf20Sopenharmony_ci
11348c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(ccw_device_set_timeout);
1135