device_ops.c

来自「linux 内核源代码」· C语言 代码 · 共 588 行 · 第 1/2 页

C
588
字号
 * Returns: *  %0, if the operation was successful; *  -%EBUSY, if the device is busy, or status pending; *  -%EACCES, if no path specified in @lpm is operational; *  -%ENODEV, if the device is not operational. * Context: *  Interrupts disabled, ccw device lock held */int ccw_device_start_timeout(struct ccw_device *cdev, struct ccw1 *cpa,			     unsigned long intparm, __u8 lpm,			     unsigned long flags, int expires){	return ccw_device_start_timeout_key(cdev, cpa, intparm, lpm,					    PAGE_DEFAULT_KEY, flags,					    expires);}/** * ccw_device_halt() - halt I/O request processing * @cdev: target ccw device * @intparm: interruption parameter; value is only used if no I/O is *	     outstanding, otherwise the intparm associated with the I/O request *	     is returned * * ccw_device_halt() calls hsch on @cdev's subchannel. * Returns: *  %0 on success, *  -%ENODEV on device not operational, *  -%EINVAL on invalid device state, *  -%EBUSY on device busy or interrupt pending. * Context: *  Interrupts disabled, ccw device lock held */int ccw_device_halt(struct ccw_device *cdev, unsigned long intparm){	struct subchannel *sch;	int ret;	if (!cdev)		return -ENODEV;	if (cdev->private->state == DEV_STATE_NOT_OPER)		return -ENODEV;	if (cdev->private->state != DEV_STATE_ONLINE &&	    cdev->private->state != DEV_STATE_W4SENSE)		return -EINVAL;	sch = to_subchannel(cdev->dev.parent);	if (!sch)		return -ENODEV;	ret = cio_halt(sch);	if (ret == 0)		cdev->private->intparm = intparm;	return ret;}/** * ccw_device_resume() - resume channel program execution * @cdev: target ccw device * * ccw_device_resume() calls rsch on @cdev's subchannel. * Returns: *  %0 on success, *  -%ENODEV on device not operational, *  -%EINVAL on invalid device state, *  -%EBUSY on device busy or interrupt pending. * Context: *  Interrupts disabled, ccw device lock held */int ccw_device_resume(struct ccw_device *cdev){	struct subchannel *sch;	if (!cdev)		return -ENODEV;	sch = to_subchannel(cdev->dev.parent);	if (!sch)		return -ENODEV;	if (cdev->private->state == DEV_STATE_NOT_OPER)		return -ENODEV;	if (cdev->private->state != DEV_STATE_ONLINE ||	    !(sch->schib.scsw.actl & SCSW_ACTL_SUSPENDED))		return -EINVAL;	return cio_resume(sch);}/* * Pass interrupt to device driver. */intccw_device_call_handler(struct ccw_device *cdev){	struct subchannel *sch;	unsigned int stctl;	int ending_status;	sch = to_subchannel(cdev->dev.parent);	/*	 * we allow for the device action handler if .	 *  - we received ending status	 *  - the action handler requested to see all interrupts	 *  - we received an intermediate status	 *  - fast notification was requested (primary status)	 *  - unsolicited interrupts	 */	stctl = cdev->private->irb.scsw.stctl;	ending_status = (stctl & SCSW_STCTL_SEC_STATUS) ||		(stctl == (SCSW_STCTL_ALERT_STATUS | SCSW_STCTL_STATUS_PEND)) ||		(stctl == SCSW_STCTL_STATUS_PEND);	if (!ending_status &&	    !cdev->private->options.repall &&	    !(stctl & SCSW_STCTL_INTER_STATUS) &&	    !(cdev->private->options.fast &&	      (stctl & SCSW_STCTL_PRIM_STATUS)))		return 0;	/* Clear pending timers for device driver initiated I/O. */	if (ending_status)		ccw_device_set_timeout(cdev, 0);	/*	 * Now we are ready to call the device driver interrupt handler.	 */	if (cdev->handler)		cdev->handler(cdev, cdev->private->intparm,			      &cdev->private->irb);	/*	 * Clear the old and now useless interrupt response block.	 */	memset(&cdev->private->irb, 0, sizeof(struct irb));	return 1;}/** * ccw_device_get_ciw() - Search for CIW command in extended sense data. * @cdev: ccw device to inspect * @ct: command type to look for * * During SenseID, command information words (CIWs) describing special * commands available to the device may have been stored in the extended * sense data. This function searches for CIWs of a specified command * type in the extended sense data. * Returns: *  %NULL if no extended sense data has been stored or if no CIW of the *  specified command type could be found, *  else a pointer to the CIW of the specified command type. */struct ciw *ccw_device_get_ciw(struct ccw_device *cdev, __u32 ct){	int ciw_cnt;	if (cdev->private->flags.esid == 0)		return NULL;	for (ciw_cnt = 0; ciw_cnt < MAX_CIWS; ciw_cnt++)		if (cdev->private->senseid.ciw[ciw_cnt].ct == ct)			return cdev->private->senseid.ciw + ciw_cnt;	return NULL;}/** * ccw_device_get_path_mask() - get currently available paths * @cdev: ccw device to be queried * Returns: *  %0 if no subchannel for the device is available, *  else the mask of currently available paths for the ccw device's subchannel. */__u8 ccw_device_get_path_mask(struct ccw_device *cdev){	struct subchannel *sch;	sch = to_subchannel(cdev->dev.parent);	if (!sch)		return 0;	else		return sch->lpm;}/* * Try to break the lock on a boxed device. */intccw_device_stlck(struct ccw_device *cdev){	void *buf, *buf2;	unsigned long flags;	struct subchannel *sch;	int ret;	if (!cdev)		return -ENODEV;	if (cdev->drv && !cdev->private->options.force)		return -EINVAL;	sch = to_subchannel(cdev->dev.parent);		CIO_TRACE_EVENT(2, "stl lock");	CIO_TRACE_EVENT(2, cdev->dev.bus_id);	buf = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);	if (!buf)		return -ENOMEM;	buf2 = kmalloc(32*sizeof(char), GFP_DMA|GFP_KERNEL);	if (!buf2) {		kfree(buf);		return -ENOMEM;	}	spin_lock_irqsave(sch->lock, flags);	ret = cio_enable_subchannel(sch, 3);	if (ret)		goto out_unlock;	/*	 * Setup ccw. We chain an unconditional reserve and a release so we	 * only break the lock.	 */	cdev->private->iccws[0].cmd_code = CCW_CMD_STLCK;	cdev->private->iccws[0].cda = (__u32) __pa(buf);	cdev->private->iccws[0].count = 32;	cdev->private->iccws[0].flags = CCW_FLAG_CC;	cdev->private->iccws[1].cmd_code = CCW_CMD_RELEASE;	cdev->private->iccws[1].cda = (__u32) __pa(buf2);	cdev->private->iccws[1].count = 32;	cdev->private->iccws[1].flags = 0;	ret = cio_start(sch, cdev->private->iccws, 0);	if (ret) {		cio_disable_subchannel(sch); //FIXME: return code?		goto out_unlock;	}	cdev->private->irb.scsw.actl |= SCSW_ACTL_START_PEND;	spin_unlock_irqrestore(sch->lock, flags);	wait_event(cdev->private->wait_q, cdev->private->irb.scsw.actl == 0);	spin_lock_irqsave(sch->lock, flags);	cio_disable_subchannel(sch); //FIXME: return code?	if ((cdev->private->irb.scsw.dstat !=	     (DEV_STAT_CHN_END|DEV_STAT_DEV_END)) ||	    (cdev->private->irb.scsw.cstat != 0))		ret = -EIO;	/* Clear irb. */	memset(&cdev->private->irb, 0, sizeof(struct irb));out_unlock:	kfree(buf);	kfree(buf2);	spin_unlock_irqrestore(sch->lock, flags);	return ret;}void *ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no){	struct subchannel *sch;	struct chp_id chpid;	sch = to_subchannel(cdev->dev.parent);	chp_id_init(&chpid);	chpid.id = sch->schib.pmcw.chpid[chp_no];	return chp_get_chp_desc(chpid);}/** * ccw_device_get_id - obtain a ccw device id * @cdev: device to obtain the id for * @dev_id: where to fill in the values */void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id){	*dev_id = cdev->private->dev_id;}EXPORT_SYMBOL(ccw_device_get_id);// FIXME: these have to go:int_ccw_device_get_subchannel_number(struct ccw_device *cdev){	return cdev->private->schid.sch_no;}MODULE_LICENSE("GPL");EXPORT_SYMBOL(ccw_device_set_options_mask);EXPORT_SYMBOL(ccw_device_set_options);EXPORT_SYMBOL(ccw_device_clear_options);EXPORT_SYMBOL(ccw_device_clear);EXPORT_SYMBOL(ccw_device_halt);EXPORT_SYMBOL(ccw_device_resume);EXPORT_SYMBOL(ccw_device_start_timeout);EXPORT_SYMBOL(ccw_device_start);EXPORT_SYMBOL(ccw_device_start_timeout_key);EXPORT_SYMBOL(ccw_device_start_key);EXPORT_SYMBOL(ccw_device_get_ciw);EXPORT_SYMBOL(ccw_device_get_path_mask);EXPORT_SYMBOL(_ccw_device_get_subchannel_number);EXPORT_SYMBOL_GPL(ccw_device_get_chp_desc);

⌨️ 快捷键说明

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