Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Handling of internal CCW device requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Copyright IBM Corp. 2009, 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Author(s): Peter Oberparleiter <peter.oberparleiter@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #define KMSG_COMPONENT "cio"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <asm/ccwdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "io_sch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "cio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include "device.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include "cio_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * lpm_adjust - adjust path mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * @lpm: path mask to adjust
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * @mask: mask of available paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Shift @lpm right until @lpm and @mask have at least one bit in common or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * until @lpm is zero. Return the resulting lpm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) int lpm_adjust(int lpm, int mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	while (lpm && ((lpm & mask) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		lpm >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  * Adjust path mask to use next path and reset retry count. Return resulting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * path mask.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) static u16 ccwreq_next_path(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	if (!req->singlepath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 		req->mask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	req->retries	= req->maxretries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	req->mask	= lpm_adjust(req->mask >> 1, req->lpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return req->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * Clean up device state and report to callback.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static void ccwreq_stop(struct ccw_device *cdev, int rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (req->done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	req->done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	ccw_device_set_timeout(cdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	memset(&cdev->private->dma_area->irb, 0, sizeof(struct irb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (rc && rc != -ENODEV && req->drc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		rc = req->drc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	req->callback(cdev, req->data, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * (Re-)Start the operation until retries and paths are exhausted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void ccwreq_do(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct subchannel *sch = to_subchannel(cdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct ccw1 *cp = req->cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	while (req->mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (req->retries-- == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 			/* Retries exhausted, try next path. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			ccwreq_next_path(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		/* Perform start function. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		memset(&cdev->private->dma_area->irb, 0, sizeof(struct irb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		rc = cio_start(sch, cp, (u8) req->mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			/* I/O started successfully. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			ccw_device_set_timeout(cdev, req->timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		if (rc == -ENODEV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			/* Permanent device error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (rc == -EACCES) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			/* Permant path error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			ccwreq_next_path(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		/* Temporary improper status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		rc = cio_clear(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ccwreq_stop(cdev, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)  * ccw_request_start - perform I/O request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)  * @cdev: ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)  * Perform the I/O request specified by cdev->req.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void ccw_request_start(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	if (req->singlepath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		/* Try all paths twice to counter link flapping. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		req->mask = 0x8080;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		req->mask = req->lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	req->retries	= req->maxretries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	req->mask	= lpm_adjust(req->mask, req->lpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	req->drc	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	req->done	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	req->cancel	= 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if (!req->mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		goto out_nopath;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	ccwreq_do(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) out_nopath:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	ccwreq_stop(cdev, -EACCES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)  * ccw_request_cancel - cancel running I/O request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * @cdev: ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * Cancel the I/O request specified by cdev->req. Return non-zero if request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  * has already finished, zero otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int ccw_request_cancel(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct subchannel *sch = to_subchannel(cdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (req->done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	req->cancel = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	rc = cio_clear(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		ccwreq_stop(cdev, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)  * Return the status of the internal I/O started on the specified ccw device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)  * Perform BASIC SENSE if required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static enum io_status ccwreq_status(struct ccw_device *cdev, struct irb *lcirb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	struct irb *irb = &cdev->private->dma_area->irb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct cmd_scsw *scsw = &irb->scsw.cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	enum uc_todo todo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	/* Perform BASIC SENSE if needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	if (ccw_device_accumulate_and_sense(cdev, lcirb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		return IO_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	/* Check for halt/clear interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (scsw->fctl & (SCSW_FCTL_HALT_FUNC | SCSW_FCTL_CLEAR_FUNC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		return IO_KILLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	/* Check for path error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	if (scsw->cc == 3 || scsw->pno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		return IO_PATH_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	/* Handle BASIC SENSE data. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (irb->esw.esw0.erw.cons) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		CIO_TRACE_EVENT(2, "sensedata");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		CIO_HEX_EVENT(2, &cdev->private->dev_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			      sizeof(struct ccw_dev_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		CIO_HEX_EVENT(2, &cdev->private->dma_area->irb.ecw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			      SENSE_MAX_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		/* Check for command reject. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (irb->ecw[0] & SNS0_CMD_REJECT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			return IO_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		/* Ask the driver what to do */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		if (cdev->drv && cdev->drv->uc_handler) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 			todo = cdev->drv->uc_handler(cdev, lcirb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 			CIO_TRACE_EVENT(2, "uc_response");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 			CIO_HEX_EVENT(2, &todo, sizeof(todo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			switch (todo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			case UC_TODO_RETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 				return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 			case UC_TODO_RETRY_ON_NEW_PATH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 				return IO_PATH_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			case UC_TODO_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 				return IO_REJECTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		/* Assume that unexpected SENSE data implies an error. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	/* Check for channel errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (scsw->cstat != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	/* Check for device errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	if (scsw->dstat & ~(DEV_STAT_CHN_END | DEV_STAT_DEV_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* Check for final state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!(scsw->dstat & DEV_STAT_DEV_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		return IO_RUNNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	/* Check for other improper status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (scsw->cc == 1 && (scsw->stctl & SCSW_STCTL_ALERT_STATUS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		return IO_STATUS_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	return IO_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * Log ccw request status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void ccwreq_log_status(struct ccw_device *cdev, enum io_status status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		struct ccw_dev_id dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		u16 retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		u8 lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}  __attribute__ ((packed)) data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	data.dev_id	= cdev->private->dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	data.retries	= req->retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	data.lpm	= (u8) req->mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	data.status	= (u8) status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	CIO_TRACE_EVENT(2, "reqstat");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	CIO_HEX_EVENT(2, &data, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * ccw_request_handler - interrupt handler for I/O request procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  * @cdev: ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  * Handle interrupt during I/O request procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) void ccw_request_handler(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	struct irb *irb = this_cpu_ptr(&cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	enum io_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	int rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	/* Check status of I/O request. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	status = ccwreq_status(cdev, irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (req->filter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		status = req->filter(cdev, req->data, irb, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (status != IO_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		ccw_device_set_timeout(cdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	if (status != IO_DONE && status != IO_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		ccwreq_log_status(cdev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	case IO_DONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	case IO_RUNNING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	case IO_REJECTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	case IO_PATH_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		goto out_next_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	case IO_STATUS_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		goto out_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	case IO_KILLED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		/* Check if request was cancelled on purpose. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (req->cancel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			rc = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		goto out_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	/* Check back with request initiator. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	if (!req->check)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	switch (req->check(cdev, req->data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	case -EAGAIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		goto out_restart;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	case -EACCES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		goto out_next_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	ccwreq_stop(cdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) out_next_path:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/* Try next path and restart I/O. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!ccwreq_next_path(cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) out_restart:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* Restart. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	ccwreq_do(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	ccwreq_stop(cdev, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * ccw_request_timeout - timeout handler for I/O request procedure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * @cdev: ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * Handle timeout during I/O request procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) void ccw_request_timeout(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	struct subchannel *sch = to_subchannel(cdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	struct ccw_request *req = &cdev->private->req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	int rc = -ENODEV, chp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	for (chp = 0; chp < 8; chp++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		if ((0x80 >> chp) & sch->schib.pmcw.lpum)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 			pr_warn("%s: No interrupt was received within %lus (CS=%02x, DS=%02x, CHPID=%x.%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 				dev_name(&cdev->dev), req->timeout / HZ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 				scsw_cstat(&sch->schib.scsw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 				scsw_dstat(&sch->schib.scsw),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 				sch->schid.cssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				sch->schib.pmcw.chpid[chp]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	if (!ccwreq_next_path(cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		/* set the final return code for this request */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		req->drc = -ETIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	rc = cio_clear(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	ccwreq_stop(cdev, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * ccw_request_notoper - notoper handler for I/O request procedure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  * @cdev: ccw device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  * Handle notoper during I/O request procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) void ccw_request_notoper(struct ccw_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	ccwreq_stop(cdev, -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }