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)  *   S/390 common I/O routines -- low level i/o calls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *    Copyright IBM Corp. 1999, 2008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *    Author(s): Ingo Adlung (adlung@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *		 Cornelia Huck (cornelia.huck@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *		 Arnd Bergmann (arndb@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *		 Martin Schwidefsky (schwidefsky@de.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define KMSG_COMPONENT "cio"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ftrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <asm/irq_regs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <asm/ipl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <asm/chpid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <asm/airq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <linux/sched/cputime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/fcx.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/crw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include "cio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "css.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include "chsc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include "ioasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include "io_sch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include "blacklist.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include "cio_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include "chp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include "trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) debug_info_t *cio_debug_msg_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) debug_info_t *cio_debug_trace_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) debug_info_t *cio_debug_crw_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) DEFINE_PER_CPU_ALIGNED(struct irb, cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) EXPORT_PER_CPU_SYMBOL(cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * Function: cio_debug_init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * Initializes three debug logs for common I/O:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * - cio_msg logs generic cio messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * - cio_trace logs the calling of different functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * - cio_crw logs machine check related cio messages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int __init cio_debug_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	cio_debug_msg_id = debug_register("cio_msg", 16, 1, 11 * sizeof(long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (!cio_debug_msg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		goto out_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	debug_register_view(cio_debug_msg_id, &debug_sprintf_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	debug_set_level(cio_debug_msg_id, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	cio_debug_trace_id = debug_register("cio_trace", 16, 1, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (!cio_debug_trace_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		goto out_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	debug_register_view(cio_debug_trace_id, &debug_hex_ascii_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	debug_set_level(cio_debug_trace_id, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	cio_debug_crw_id = debug_register("cio_crw", 8, 1, 8 * sizeof(long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (!cio_debug_crw_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		goto out_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	debug_register_view(cio_debug_crw_id, &debug_sprintf_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	debug_set_level(cio_debug_crw_id, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) out_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	debug_unregister(cio_debug_msg_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	debug_unregister(cio_debug_trace_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	debug_unregister(cio_debug_crw_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) arch_initcall (cio_debug_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) int cio_set_options(struct subchannel *sch, int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	struct io_subchannel_private *priv = to_io_private(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	priv->options.suspend = (flags & DOIO_ALLOW_SUSPEND) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	priv->options.prefetch = (flags & DOIO_DENY_PREFETCH) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	priv->options.inter = (flags & DOIO_SUPPRESS_INTER) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) cio_start_handle_notoper(struct subchannel *sch, __u8 lpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	char dbf_text[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	if (lpm != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		sch->lpm &= ~lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		sch->lpm = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	CIO_MSG_EVENT(2, "cio_start: 'not oper' status for "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		      "subchannel 0.%x.%04x!\n", sch->schid.ssid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		      sch->schid.sch_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	sprintf(dbf_text, "no%s", dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	CIO_TRACE_EVENT(0, dbf_text);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	CIO_HEX_EVENT(0, &sch->schib, sizeof (struct schib));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return (sch->lpm ? -EACCES : -ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) cio_start_key (struct subchannel *sch,	/* subchannel structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	       struct ccw1 * cpa,	/* logical channel prog addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	       __u8 lpm,		/* logical path mask */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	       __u8 key)                /* storage key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct io_subchannel_private *priv = to_io_private(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	union orb *orb = &priv->orb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	int ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	CIO_TRACE_EVENT(5, "stIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	CIO_TRACE_EVENT(5, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	memset(orb, 0, sizeof(union orb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	/* sch is always under 2G. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	orb->cmd.intparm = (u32)(addr_t)sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	orb->cmd.fmt = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	orb->cmd.pfch = priv->options.prefetch == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	orb->cmd.spnd = priv->options.suspend;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	orb->cmd.ssic = priv->options.suspend && priv->options.inter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	orb->cmd.lpm = (lpm != 0) ? lpm : sch->lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	 * for 64 bit we always support 64 bit IDAWs with 4k page size only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	orb->cmd.c64 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	orb->cmd.i2k = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	orb->cmd.key = key >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* issue "Start Subchannel" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	orb->cmd.cpa = (__u32) __pa(cpa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	ccode = ssch(sch->schid, orb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	/* process condition code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	CIO_HEX_EVENT(5, &ccode, sizeof(ccode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		 * initialize device status information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		sch->schib.scsw.cmd.actl |= SCSW_ACTL_START_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	case 1:		/* status pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	case 2:		/* busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	case 3:		/* device/path not operational */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		return cio_start_handle_notoper(sch, lpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) EXPORT_SYMBOL_GPL(cio_start_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) cio_start (struct subchannel *sch, struct ccw1 *cpa, __u8 lpm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	return cio_start_key(sch, cpa, lpm, PAGE_DEFAULT_KEY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) EXPORT_SYMBOL_GPL(cio_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  * resume suspended I/O operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) cio_resume (struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	int ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	CIO_TRACE_EVENT(4, "resIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	CIO_TRACE_EVENT(4, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ccode = rsch (sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	CIO_HEX_EVENT(4, &ccode, sizeof(ccode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		sch->schib.scsw.cmd.actl |= SCSW_ACTL_RESUME_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		 * useless to wait for request completion
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		 *  as device is no longer operational !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) EXPORT_SYMBOL_GPL(cio_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  * halt I/O operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) cio_halt(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (!sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	CIO_TRACE_EVENT(2, "haltIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	CIO_TRACE_EVENT(2, dev_name(&sch->dev));
^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) 	 * Issue "Halt subchannel" and process condition code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	ccode = hsch (sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		sch->schib.scsw.cmd.actl |= SCSW_ACTL_HALT_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	case 1:		/* status pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	case 2:		/* busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	default:		/* device not operational */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) EXPORT_SYMBOL_GPL(cio_halt);
^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)  * Clear I/O operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) cio_clear(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (!sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	CIO_TRACE_EVENT(2, "clearIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	CIO_TRACE_EVENT(2, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	 * Issue "Clear subchannel" and process condition code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	ccode = csch (sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		sch->schib.scsw.cmd.actl |= SCSW_ACTL_CLEAR_PEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	default:		/* device not operational */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) EXPORT_SYMBOL_GPL(cio_clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * Function: cio_cancel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  * Issues a "Cancel Subchannel" on the specified subchannel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)  * Note: We don't need any fancy intparms and flags here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)  *	 since xsch is executed synchronously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)  * Only for common I/O internal use as for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) cio_cancel (struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	int ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (!sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	CIO_TRACE_EVENT(2, "cancelIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	CIO_TRACE_EVENT(2, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	ccode = xsch (sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	CIO_HEX_EVENT(2, &ccode, sizeof(ccode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	case 0:		/* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		/* Update information in scsw. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	case 1:		/* status pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	case 2:		/* not applicable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	default:	/* not oper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) EXPORT_SYMBOL_GPL(cio_cancel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * cio_cancel_halt_clear - Cancel running I/O by performing cancel, halt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  * and clear ordinally if subchannel is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * @sch: subchannel on which to perform the cancel_halt_clear operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * @iretry: the number of the times remained to retry the next operation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * This should be called repeatedly since halt/clear are asynchronous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  * operations. We do one try with cio_cancel, three tries with cio_halt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)  * 255 tries with cio_clear. The caller should initialize @iretry with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)  * the value 255 for its first call to this, and keep using the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)  * @iretry in the subsequent calls until it gets a non -EBUSY return.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)  * Returns 0 if device now idle, -ENODEV for device not operational,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)  * -EBUSY if an interrupt is expected (either from halt/clear or from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)  * status pending), and -EIO if out of retries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int cio_cancel_halt_clear(struct subchannel *sch, int *iretry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	if (!sch->schib.pmcw.ena)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		/* Not operational -> done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	/* Stage 1: cancel io. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_HALT_PEND) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	    !(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		if (!scsw_is_tm(&sch->schib.scsw)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			ret = cio_cancel(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 			if (ret != -EINVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		 * Cancel io unsuccessful or not applicable (transport mode).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		 * Continue with asynchronous instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		*iretry = 3;	/* 3 halt retries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/* Stage 2: halt io. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	if (!(scsw_actl(&sch->schib.scsw) & SCSW_ACTL_CLEAR_PEND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		if (*iretry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 			*iretry -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 			ret = cio_halt(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 			if (ret != -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				return (ret == 0) ? -EBUSY : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		/* Halt io unsuccessful. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		*iretry = 255;	/* 255 clear retries. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	/* Stage 3: clear io. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (*iretry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		*iretry -= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		ret = cio_clear(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		return (ret == 0) ? -EBUSY : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* Function was unsuccessful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) EXPORT_SYMBOL_GPL(cio_cancel_halt_clear);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) static void cio_apply_config(struct subchannel *sch, struct schib *schib)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	schib->pmcw.intparm = sch->config.intparm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	schib->pmcw.mbi = sch->config.mbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	schib->pmcw.isc = sch->config.isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	schib->pmcw.ena = sch->config.ena;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	schib->pmcw.mme = sch->config.mme;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	schib->pmcw.mp = sch->config.mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	schib->pmcw.csense = sch->config.csense;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	schib->pmcw.mbfc = sch->config.mbfc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	if (sch->config.mbfc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		schib->mba = sch->config.mba;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) static int cio_check_config(struct subchannel *sch, struct schib *schib)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	return (schib->pmcw.intparm == sch->config.intparm) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		(schib->pmcw.mbi == sch->config.mbi) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		(schib->pmcw.isc == sch->config.isc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		(schib->pmcw.ena == sch->config.ena) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		(schib->pmcw.mme == sch->config.mme) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		(schib->pmcw.mp == sch->config.mp) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		(schib->pmcw.csense == sch->config.csense) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		(schib->pmcw.mbfc == sch->config.mbfc) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		(!sch->config.mbfc || (schib->mba == sch->config.mba));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)  * cio_commit_config - apply configuration to the subchannel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) int cio_commit_config(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	int ccode, retry, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	struct irb irb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	for (retry = 0; retry < 5; retry++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		/* copy desired changes to local schib */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 		cio_apply_config(sch, &schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 		ccode = msch(sch->schid, &schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		if (ccode < 0) /* -EIO if msch gets a program check. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 			return ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		switch (ccode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		case 0: /* successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 			if (stsch(sch->schid, &schib) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 			    !css_sch_is_valid(&schib))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 				return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			if (cio_check_config(sch, &schib)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 				/* commit changes from local schib */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 				memcpy(&sch->schib, &schib, sizeof(schib));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 				return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			ret = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		case 1: /* status pending */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			if (tsch(sch->schid, &irb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 				return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		case 2: /* busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			udelay(100); /* allow for recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		case 3: /* not operational */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) EXPORT_SYMBOL_GPL(cio_commit_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)  * cio_update_schib - Perform stsch and update schib if subchannel is valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)  * @sch: subchannel on which to perform stsch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)  * Return zero on success, -ENODEV otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) int cio_update_schib(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (stsch(sch->schid, &schib) || !css_sch_is_valid(&schib))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	memcpy(&sch->schib, &schib, sizeof(schib));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) EXPORT_SYMBOL_GPL(cio_update_schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)  * cio_enable_subchannel - enable a subchannel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)  * @sch: subchannel to be enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)  * @intparm: interruption parameter to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) int cio_enable_subchannel(struct subchannel *sch, u32 intparm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	CIO_TRACE_EVENT(2, "ensch");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	CIO_TRACE_EVENT(2, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	if (sch_is_pseudo_sch(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	sch->config.ena = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	sch->config.isc = sch->isc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	sch->config.intparm = intparm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	ret = cio_commit_config(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	if (ret == -EIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		 * Got a program check in msch. Try without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		 * the concurrent sense bit the next time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		sch->config.csense = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 		ret = cio_commit_config(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	CIO_HEX_EVENT(2, &ret, sizeof(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) EXPORT_SYMBOL_GPL(cio_enable_subchannel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)  * cio_disable_subchannel - disable a subchannel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)  * @sch: subchannel to disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int cio_disable_subchannel(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	CIO_TRACE_EVENT(2, "dissch");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 	CIO_TRACE_EVENT(2, dev_name(&sch->dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	if (sch_is_pseudo_sch(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (cio_update_schib(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	sch->config.ena = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	ret = cio_commit_config(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 	CIO_HEX_EVENT(2, &ret, sizeof(ret));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) EXPORT_SYMBOL_GPL(cio_disable_subchannel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  * do_cio_interrupt() handles all normal I/O device IRQ's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static irqreturn_t do_cio_interrupt(int irq, void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	struct tpi_info *tpi_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	struct subchannel *sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	struct irb *irb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	set_cpu_flag(CIF_NOHZ_DELAY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	tpi_info = (struct tpi_info *) &get_irq_regs()->int_code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	trace_s390_cio_interrupt(tpi_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	irb = this_cpu_ptr(&cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	sch = (struct subchannel *)(unsigned long) tpi_info->intparm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	if (!sch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 		/* Clear pending interrupt condition. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 		inc_irq_stat(IRQIO_CIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 		tsch(tpi_info->schid, irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	spin_lock(sch->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	/* Store interrupt response block to lowcore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 	if (tsch(tpi_info->schid, irb) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		/* Keep subchannel information word up to date. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		memcpy (&sch->schib.scsw, &irb->scsw, sizeof (irb->scsw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 		/* Call interrupt handler if there is one. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		if (sch->driver && sch->driver->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			sch->driver->irq(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 			inc_irq_stat(IRQIO_CIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 		inc_irq_stat(IRQIO_CIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	spin_unlock(sch->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) void __init init_cio_interrupts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	irq_set_chip_and_handler(IO_INTERRUPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 				 &dummy_irq_chip, handle_percpu_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 	if (request_irq(IO_INTERRUPT, do_cio_interrupt, 0, "I/O", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		panic("Failed to register I/O interrupt\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) #ifdef CONFIG_CCW_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) static struct subchannel *console_sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) static struct lock_class_key console_sch_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)  * Use cio_tsch to update the subchannel status and call the interrupt handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580)  * if status had been pending. Called with the subchannel's lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) void cio_tsch(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	struct irb *irb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	int irq_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	irb = this_cpu_ptr(&cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	/* Store interrupt response block to lowcore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	if (tsch(sch->schid, irb) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 		/* Not status pending or not operational. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 	memcpy(&sch->schib.scsw, &irb->scsw, sizeof(union scsw));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	/* Call interrupt handler with updated status. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	irq_context = in_interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	if (!irq_context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 		local_bh_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 		irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	kstat_incr_irq_this_cpu(IO_INTERRUPT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	if (sch->driver && sch->driver->irq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		sch->driver->irq(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		inc_irq_stat(IRQIO_CIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	if (!irq_context) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 		irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 		_local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static int cio_test_for_console(struct subchannel_id schid, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	if (stsch(schid, &schib) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if ((schib.pmcw.st == SUBCHANNEL_TYPE_IO) && schib.pmcw.dnv &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	    (schib.pmcw.dev == console_devno)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 		console_irq = schid.sch_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 		return 1; /* found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) static int cio_get_console_sch_no(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 	struct subchannel_id schid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	init_subchannel_id(&schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	if (console_irq != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		/* VM provided us with the irq number of the console. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 		schid.sch_no = console_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		if (stsch(schid, &schib) != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 		    (schib.pmcw.st != SUBCHANNEL_TYPE_IO) || !schib.pmcw.dnv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 			return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 		console_devno = schib.pmcw.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	} else if (console_devno != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		/* At least the console device number is known. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 		for_each_subchannel(cio_test_for_console, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	return console_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) struct subchannel *cio_probe_console(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	struct subchannel_id schid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	struct subchannel *sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	int sch_no, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	sch_no = cio_get_console_sch_no();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	if (sch_no == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 		pr_warn("No CCW console was found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	init_subchannel_id(&schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 	schid.sch_no = sch_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	ret = stsch(schid, &schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		return ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	sch = css_alloc_subchannel(schid, &schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (IS_ERR(sch))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		return sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 	lockdep_set_class(sch->lock, &console_sch_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	isc_register(CONSOLE_ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	sch->config.isc = CONSOLE_ISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 	sch->config.intparm = (u32)(addr_t)sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	ret = cio_commit_config(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 		isc_unregister(CONSOLE_ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 		put_device(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 	console_sch = sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	return sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int cio_is_console(struct subchannel_id schid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	if (!console_sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	return schid_equal(&schid, &console_sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) void cio_register_early_subchannels(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 	if (!console_sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	ret = css_register_subchannel(console_sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 		put_device(&console_sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) #endif /* CONFIG_CCW_CONSOLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)  * cio_tm_start_key - perform start function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)  * @sch: subchannel on which to perform the start function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)  * @tcw: transport-command word to be started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)  * @lpm: mask of paths to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)  * @key: storage key to use for storage access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707)  * Start the tcw on the given subchannel. Return zero on success, non-zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)  * otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) int cio_tm_start_key(struct subchannel *sch, struct tcw *tcw, u8 lpm, u8 key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	union orb *orb = &to_io_private(sch)->orb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	memset(orb, 0, sizeof(union orb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	orb->tm.intparm = (u32) (addr_t) sch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 	orb->tm.key = key >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 	orb->tm.b = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	orb->tm.lpm = lpm ? lpm : sch->lpm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 	orb->tm.tcw = (u32) (addr_t) tcw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	cc = ssch(sch->schid, orb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	switch (cc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) 		return cio_start_handle_notoper(sch, lpm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) EXPORT_SYMBOL_GPL(cio_tm_start_key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735)  * cio_tm_intrg - perform interrogate function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)  * @sch: subchannel on which to perform the interrogate function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738)  * If the specified subchannel is running in transport-mode, perform the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)  * interrogate function. Return zero on success, non-zero otherwie.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) int cio_tm_intrg(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 	int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 	if (!to_io_private(sch)->orb.tm.b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	cc = xsch(sch->schid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	switch (cc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 	case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) EXPORT_SYMBOL_GPL(cio_tm_intrg);