⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 device_fsm.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * drivers/s390/cio/device_fsm.c * finite state machine for device handling * *    Copyright (C) 2002 IBM Deutschland Entwicklung GmbH, *			 IBM Corporation *    Author(s): Cornelia Huck(cohuck@de.ibm.com) *		 Martin Schwidefsky (schwidefsky@de.ibm.com) */#include <linux/module.h>#include <linux/config.h>#include <linux/init.h>#include <linux/jiffies.h>#include <linux/string.h>#include <asm/ccwdev.h>#include <asm/cio.h>#include "cio.h"#include "cio_debug.h"#include "css.h"#include "device.h"#include "chsc.h"#include "ioasm.h"intdevice_is_online(struct subchannel *sch){	struct ccw_device *cdev;	if (!sch->dev.driver_data)		return 0;	cdev = sch->dev.driver_data;	return (cdev->private->state == DEV_STATE_ONLINE);}intdevice_is_disconnected(struct subchannel *sch){	struct ccw_device *cdev;	if (!sch->dev.driver_data)		return 0;	cdev = sch->dev.driver_data;	return (cdev->private->state == DEV_STATE_DISCONNECTED ||		cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID);}voiddevice_set_disconnected(struct subchannel *sch){	struct ccw_device *cdev;	if (!sch->dev.driver_data)		return;	cdev = sch->dev.driver_data;	ccw_device_set_timeout(cdev, 0);	cdev->private->flags.fake_irb = 0;	cdev->private->state = DEV_STATE_DISCONNECTED;}voiddevice_set_waiting(struct subchannel *sch){	struct ccw_device *cdev;	if (!sch->dev.driver_data)		return;	cdev = sch->dev.driver_data;	ccw_device_set_timeout(cdev, 10*HZ);	cdev->private->state = DEV_STATE_WAIT4IO;}/* * Timeout function. It just triggers a DEV_EVENT_TIMEOUT. */static voidccw_device_timeout(unsigned long data){	struct ccw_device *cdev;	cdev = (struct ccw_device *) data;	spin_lock_irq(cdev->ccwlock);	dev_fsm_event(cdev, DEV_EVENT_TIMEOUT);	spin_unlock_irq(cdev->ccwlock);}/* * Set timeout */voidccw_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);}/* Kill any pending timers after machine check. */voiddevice_kill_pending_timer(struct subchannel *sch){	struct ccw_device *cdev;	if (!sch->dev.driver_data)		return;	cdev = sch->dev.driver_data;	ccw_device_set_timeout(cdev, 0);}/* * 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). */intccw_device_cancel_halt_clear(struct ccw_device *cdev){	struct subchannel *sch;	int ret;	sch = to_subchannel(cdev->dev.parent);	ret = stsch(sch->irq, &sch->schib);	if (ret || !sch->schib.pmcw.dnv)		return -ENODEV; 	if (!sch->schib.pmcw.ena || sch->schib.scsw.actl == 0)		/* Not operational or no activity -> done. */		return 0;	/* Stage 1: cancel io. */	if (!(sch->schib.scsw.actl & SCSW_ACTL_HALT_PEND) &&	    !(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {		ret = cio_cancel(sch);		if (ret != -EINVAL)			return ret;		/* cancel io unsuccessful. From now on it is asynchronous. */		cdev->private->iretry = 3;	/* 3 halt retries. */	}	if (!(sch->schib.scsw.actl & SCSW_ACTL_CLEAR_PEND)) {		/* Stage 2: halt io. */		if (cdev->private->iretry) {			cdev->private->iretry--;			ret = cio_halt(sch);			return (ret == 0) ? -EBUSY : ret;		}		/* 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");}static intccw_device_handle_oper(struct ccw_device *cdev){	struct subchannel *sch;	sch = to_subchannel(cdev->dev.parent);	cdev->private->flags.recog_done = 1;	/*	 * Check if cu type and device type still match. If	 * not, it is certainly another device and we have to	 * de- and re-register. Also check here for non-matching devno.	 */	if (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 ||	    cdev->private->devno != sch->schib.pmcw.dev) {		PREPARE_WORK(&cdev->private->kick_work,			     ccw_device_do_unreg_rereg, (void *)cdev);		queue_work(ccw_device_work, &cdev->private->kick_work);		return 0;	}	cdev->private->flags.donotify = 1;	return 1;}/* * 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). */static inline void__recover_lost_chpids(struct subchannel *sch, int old_lpm){	int mask, i;	for (i = 0; i<8; i++) {		mask = 0x80 >> i;		if (!(sch->lpm & mask))			continue;		if (old_lpm & mask)			continue;		chpid_is_actually_online(sch->schib.pmcw.chpid[i]);	}}/* * Stop device recognition. */static voidccw_device_recog_done(struct ccw_device *cdev, int state){	struct subchannel *sch;	int notify, old_lpm, same_dev;	sch = to_subchannel(cdev->dev.parent);	ccw_device_set_timeout(cdev, 0);	cio_disable_subchannel(sch);	/*	 * Now that we tried recognition, we have performed device selection	 * through ssch() and the path information is up to date.	 */	old_lpm = sch->lpm;	stsch(sch->irq, &sch->schib);	sch->lpm = sch->schib.pmcw.pim &		sch->schib.pmcw.pam &		sch->schib.pmcw.pom &		sch->opm;	/* Check since device may again have become not operational. */	if (!sch->schib.pmcw.dnv)		state = DEV_STATE_NOT_OPER;	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);	if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {		if (state == DEV_STATE_NOT_OPER) {			cdev->private->flags.recog_done = 1;			cdev->private->state = DEV_STATE_DISCONNECTED;			return;		}		/* Boxed devices don't need extra treatment. */	}	notify = 0;	same_dev = 0; /* Keep the compiler quiet... */	switch (state) {	case DEV_STATE_NOT_OPER:		CIO_DEBUG(KERN_WARNING, 2,			  "SenseID : unknown device %04x on subchannel %04x\n",			  cdev->private->devno, sch->irq);		break;	case DEV_STATE_OFFLINE:		if (cdev->private->state == DEV_STATE_DISCONNECTED_SENSE_ID) {			same_dev = ccw_device_handle_oper(cdev);			notify = 1;		}		/* fill out sense information */		cdev->id = (struct ccw_device_id) {			.cu_type   = cdev->private->senseid.cu_type,			.cu_model  = cdev->private->senseid.cu_model,			.dev_type  = cdev->private->senseid.dev_type,			.dev_model = cdev->private->senseid.dev_model,		};		if (notify) {			cdev->private->state = DEV_STATE_OFFLINE;			if (same_dev) {				/* Get device online again. */				ccw_device_online(cdev);				wake_up(&cdev->private->wait_q);			}			return;		}		/* Issue device info message. */		CIO_DEBUG(KERN_INFO, 2, "SenseID : device %04x reports: "			  "CU  Type/Mod = %04X/%02X, Dev Type/Mod = "			  "%04X/%02X\n", cdev->private->devno,			  cdev->id.cu_type, cdev->id.cu_model,			  cdev->id.dev_type, cdev->id.dev_model);		break;	case DEV_STATE_BOXED:		CIO_DEBUG(KERN_WARNING, 2,			  "SenseID : boxed device %04x on subchannel %04x\n",			  cdev->private->devno, sch->irq);		break;	}	cdev->private->state = state;	io_subchannel_recog_done(cdev);	if (state != DEV_STATE_NOT_OPER)		wake_up(&cdev->private->wait_q);}/* * Function called from device_id.c after sense id has completed. */voidccw_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;	}}static voidccw_device_oper_notify(void *data){	struct ccw_device *cdev;	struct subchannel *sch;	int ret;	cdev = (struct ccw_device *)data;	sch = to_subchannel(cdev->dev.parent);	ret = (sch->driver && sch->driver->notify) ?		sch->driver->notify(&sch->dev, CIO_OPER) : 0;	if (!ret)		/* Driver doesn't want device back. */		ccw_device_do_unreg_rereg((void *)cdev);	else		wake_up(&cdev->private->wait_q);}/* * Finished with online/offline processing. */static voidccw_device_done(struct ccw_device *cdev, int state){	struct subchannel *sch;	sch = to_subchannel(cdev->dev.parent);	if (state != DEV_STATE_ONLINE)		cio_disable_subchannel(sch);	/* Reset device status. */	memset(&cdev->private->irb, 0, sizeof(struct irb));	cdev->private->state = state;	if (state == DEV_STATE_BOXED)		CIO_DEBUG(KERN_WARNING, 2,			  "Boxed device %04x on subchannel %04x\n",			  cdev->private->devno, sch->irq);	if (cdev->private->flags.donotify) {		cdev->private->flags.donotify = 0;		PREPARE_WORK(&cdev->private->kick_work, ccw_device_oper_notify,			     (void *)cdev);		queue_work(ccw_device_notify_work, &cdev->private->kick_work);	}	wake_up(&cdev->private->wait_q);	if (css_init_done && state != DEV_STATE_ONLINE)		put_device (&cdev->dev);}/* * Function called from device_pgid.c after sense path ground has completed. */voidccw_device_sense_pgid_done(struct ccw_device *cdev, int err){	struct subchannel *sch;	sch = to_subchannel(cdev->dev.parent);	switch (err) {	case 0:		/* Start Path Group verification. */		sch->vpm = 0;	/* Start with no path groups set. */		cdev->private->state = DEV_STATE_VERIFY;		ccw_device_verify_start(cdev);		break;	case -ETIME:		/* Sense path group id stopped by timeout. */	case -EUSERS:		/* device is reserved for someone else. */		ccw_device_done(cdev, DEV_STATE_BOXED);		break;	case -EOPNOTSUPP: /* path grouping not supported, just set online. */		cdev->private->options.pgroup = 0;		ccw_device_done(cdev, DEV_STATE_ONLINE);		break;	default:		ccw_device_done(cdev, DEV_STATE_NOT_OPER);		break;	}}/* * Start device recognition. */intccw_device_recognition(struct ccw_device *cdev){	struct subchannel *sch;	int ret;	if ((cdev->private->state != DEV_STATE_NOT_OPER) &&	    (cdev->private->state != DEV_STATE_BOXED))		return -EINVAL;	sch = to_subchannel(cdev->dev.parent);	ret = cio_enable_subchannel(sch, sch->schib.pmcw.isc);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -