xref: /openbmc/linux/drivers/s390/cio/chsc_sch.c (revision 5a0e3ad6af8660be21ca98a971cd00f331318c05)
19d92a7e1SCornelia Huck /*
29d92a7e1SCornelia Huck  * Driver for s390 chsc subchannels
39d92a7e1SCornelia Huck  *
4ad285ae9SCornelia Huck  * Copyright IBM Corp. 2008, 2009
5ad285ae9SCornelia Huck  *
69d92a7e1SCornelia Huck  * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
79d92a7e1SCornelia Huck  *
89d92a7e1SCornelia Huck  */
99d92a7e1SCornelia Huck 
10*5a0e3ad6STejun Heo #include <linux/slab.h>
119d92a7e1SCornelia Huck #include <linux/device.h>
129d92a7e1SCornelia Huck #include <linux/module.h>
139d92a7e1SCornelia Huck #include <linux/uaccess.h>
149d92a7e1SCornelia Huck #include <linux/miscdevice.h>
159d92a7e1SCornelia Huck 
1644ee6a85SHeiko Carstens #include <asm/compat.h>
179d92a7e1SCornelia Huck #include <asm/cio.h>
189d92a7e1SCornelia Huck #include <asm/chsc.h>
199d92a7e1SCornelia Huck #include <asm/isc.h>
209d92a7e1SCornelia Huck 
219d92a7e1SCornelia Huck #include "cio.h"
229d92a7e1SCornelia Huck #include "cio_debug.h"
239d92a7e1SCornelia Huck #include "css.h"
249d92a7e1SCornelia Huck #include "chsc_sch.h"
259d92a7e1SCornelia Huck #include "ioasm.h"
269d92a7e1SCornelia Huck 
279d92a7e1SCornelia Huck static debug_info_t *chsc_debug_msg_id;
289d92a7e1SCornelia Huck static debug_info_t *chsc_debug_log_id;
299d92a7e1SCornelia Huck 
309d92a7e1SCornelia Huck #define CHSC_MSG(imp, args...) do {					\
319d92a7e1SCornelia Huck 		debug_sprintf_event(chsc_debug_msg_id, imp , ##args);	\
329d92a7e1SCornelia Huck 	} while (0)
339d92a7e1SCornelia Huck 
349d92a7e1SCornelia Huck #define CHSC_LOG(imp, txt) do {					\
359d92a7e1SCornelia Huck 		debug_text_event(chsc_debug_log_id, imp , txt);	\
369d92a7e1SCornelia Huck 	} while (0)
379d92a7e1SCornelia Huck 
389d92a7e1SCornelia Huck static void CHSC_LOG_HEX(int level, void *data, int length)
399d92a7e1SCornelia Huck {
409d92a7e1SCornelia Huck 	while (length > 0) {
419d92a7e1SCornelia Huck 		debug_event(chsc_debug_log_id, level, data, length);
429d92a7e1SCornelia Huck 		length -= chsc_debug_log_id->buf_size;
439d92a7e1SCornelia Huck 		data += chsc_debug_log_id->buf_size;
449d92a7e1SCornelia Huck 	}
459d92a7e1SCornelia Huck }
469d92a7e1SCornelia Huck 
479d92a7e1SCornelia Huck MODULE_AUTHOR("IBM Corporation");
489d92a7e1SCornelia Huck MODULE_DESCRIPTION("driver for s390 chsc subchannels");
499d92a7e1SCornelia Huck MODULE_LICENSE("GPL");
509d92a7e1SCornelia Huck 
519d92a7e1SCornelia Huck static void chsc_subchannel_irq(struct subchannel *sch)
529d92a7e1SCornelia Huck {
539d92a7e1SCornelia Huck 	struct chsc_private *private = sch->private;
549d92a7e1SCornelia Huck 	struct chsc_request *request = private->request;
55cbb870c8SHeiko Carstens 	struct irb *irb = (struct irb *)&S390_lowcore.irb;
569d92a7e1SCornelia Huck 
579d92a7e1SCornelia Huck 	CHSC_LOG(4, "irb");
589d92a7e1SCornelia Huck 	CHSC_LOG_HEX(4, irb, sizeof(*irb));
599d92a7e1SCornelia Huck 	/* Copy irb to provided request and set done. */
609d92a7e1SCornelia Huck 	if (!request) {
619d92a7e1SCornelia Huck 		CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
629d92a7e1SCornelia Huck 			 sch->schid.ssid, sch->schid.sch_no);
639d92a7e1SCornelia Huck 		return;
649d92a7e1SCornelia Huck 	}
659d92a7e1SCornelia Huck 	private->request = NULL;
669d92a7e1SCornelia Huck 	memcpy(&request->irb, irb, sizeof(*irb));
67cdb912a4SSebastian Ott 	cio_update_schib(sch);
689d92a7e1SCornelia Huck 	complete(&request->completion);
699d92a7e1SCornelia Huck 	put_device(&sch->dev);
709d92a7e1SCornelia Huck }
719d92a7e1SCornelia Huck 
729d92a7e1SCornelia Huck static int chsc_subchannel_probe(struct subchannel *sch)
739d92a7e1SCornelia Huck {
749d92a7e1SCornelia Huck 	struct chsc_private *private;
759d92a7e1SCornelia Huck 	int ret;
769d92a7e1SCornelia Huck 
779d92a7e1SCornelia Huck 	CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
789d92a7e1SCornelia Huck 		 sch->schid.ssid, sch->schid.sch_no);
799d92a7e1SCornelia Huck 	sch->isc = CHSC_SCH_ISC;
809d92a7e1SCornelia Huck 	private = kzalloc(sizeof(*private), GFP_KERNEL);
819d92a7e1SCornelia Huck 	if (!private)
829d92a7e1SCornelia Huck 		return -ENOMEM;
839d92a7e1SCornelia Huck 	ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
849d92a7e1SCornelia Huck 	if (ret) {
859d92a7e1SCornelia Huck 		CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
869d92a7e1SCornelia Huck 			 sch->schid.ssid, sch->schid.sch_no, ret);
879d92a7e1SCornelia Huck 		kfree(private);
889d92a7e1SCornelia Huck 	} else {
899d92a7e1SCornelia Huck 		sch->private = private;
90f67f129eSMing Lei 		if (dev_get_uevent_suppress(&sch->dev)) {
91f67f129eSMing Lei 			dev_set_uevent_suppress(&sch->dev, 0);
929d92a7e1SCornelia Huck 			kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
939d92a7e1SCornelia Huck 		}
949d92a7e1SCornelia Huck 	}
959d92a7e1SCornelia Huck 	return ret;
969d92a7e1SCornelia Huck }
979d92a7e1SCornelia Huck 
989d92a7e1SCornelia Huck static int chsc_subchannel_remove(struct subchannel *sch)
999d92a7e1SCornelia Huck {
1009d92a7e1SCornelia Huck 	struct chsc_private *private;
1019d92a7e1SCornelia Huck 
1029d92a7e1SCornelia Huck 	cio_disable_subchannel(sch);
1039d92a7e1SCornelia Huck 	private = sch->private;
1049d92a7e1SCornelia Huck 	sch->private = NULL;
1059d92a7e1SCornelia Huck 	if (private->request) {
1069d92a7e1SCornelia Huck 		complete(&private->request->completion);
1079d92a7e1SCornelia Huck 		put_device(&sch->dev);
1089d92a7e1SCornelia Huck 	}
1099d92a7e1SCornelia Huck 	kfree(private);
1109d92a7e1SCornelia Huck 	return 0;
1119d92a7e1SCornelia Huck }
1129d92a7e1SCornelia Huck 
1139d92a7e1SCornelia Huck static void chsc_subchannel_shutdown(struct subchannel *sch)
1149d92a7e1SCornelia Huck {
1159d92a7e1SCornelia Huck 	cio_disable_subchannel(sch);
1169d92a7e1SCornelia Huck }
1179d92a7e1SCornelia Huck 
118ad285ae9SCornelia Huck static int chsc_subchannel_prepare(struct subchannel *sch)
119ad285ae9SCornelia Huck {
120ad285ae9SCornelia Huck 	int cc;
121ad285ae9SCornelia Huck 	struct schib schib;
122ad285ae9SCornelia Huck 	/*
123ad285ae9SCornelia Huck 	 * Don't allow suspend while the subchannel is not idle
124ad285ae9SCornelia Huck 	 * since we don't have a way to clear the subchannel and
125ad285ae9SCornelia Huck 	 * cannot disable it with a request running.
126ad285ae9SCornelia Huck 	 */
127ad285ae9SCornelia Huck 	cc = stsch(sch->schid, &schib);
128ad285ae9SCornelia Huck 	if (!cc && scsw_stctl(&schib.scsw))
129ad285ae9SCornelia Huck 		return -EAGAIN;
130ad285ae9SCornelia Huck 	return 0;
131ad285ae9SCornelia Huck }
132ad285ae9SCornelia Huck 
133ad285ae9SCornelia Huck static int chsc_subchannel_freeze(struct subchannel *sch)
134ad285ae9SCornelia Huck {
135ad285ae9SCornelia Huck 	return cio_disable_subchannel(sch);
136ad285ae9SCornelia Huck }
137ad285ae9SCornelia Huck 
138ad285ae9SCornelia Huck static int chsc_subchannel_restore(struct subchannel *sch)
139ad285ae9SCornelia Huck {
140ad285ae9SCornelia Huck 	return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
141ad285ae9SCornelia Huck }
142ad285ae9SCornelia Huck 
1439d92a7e1SCornelia Huck static struct css_device_id chsc_subchannel_ids[] = {
1449d92a7e1SCornelia Huck 	{ .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
1459d92a7e1SCornelia Huck 	{ /* end of list */ },
1469d92a7e1SCornelia Huck };
1479d92a7e1SCornelia Huck MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
1489d92a7e1SCornelia Huck 
1499d92a7e1SCornelia Huck static struct css_driver chsc_subchannel_driver = {
1509d92a7e1SCornelia Huck 	.owner = THIS_MODULE,
1519d92a7e1SCornelia Huck 	.subchannel_type = chsc_subchannel_ids,
1529d92a7e1SCornelia Huck 	.irq = chsc_subchannel_irq,
1539d92a7e1SCornelia Huck 	.probe = chsc_subchannel_probe,
1549d92a7e1SCornelia Huck 	.remove = chsc_subchannel_remove,
1559d92a7e1SCornelia Huck 	.shutdown = chsc_subchannel_shutdown,
156ad285ae9SCornelia Huck 	.prepare = chsc_subchannel_prepare,
157ad285ae9SCornelia Huck 	.freeze = chsc_subchannel_freeze,
158ad285ae9SCornelia Huck 	.thaw = chsc_subchannel_restore,
159ad285ae9SCornelia Huck 	.restore = chsc_subchannel_restore,
1609d92a7e1SCornelia Huck 	.name = "chsc_subchannel",
1619d92a7e1SCornelia Huck };
1629d92a7e1SCornelia Huck 
1639d92a7e1SCornelia Huck static int __init chsc_init_dbfs(void)
1649d92a7e1SCornelia Huck {
1659d92a7e1SCornelia Huck 	chsc_debug_msg_id = debug_register("chsc_msg", 16, 1,
1669d92a7e1SCornelia Huck 					   16 * sizeof(long));
1679d92a7e1SCornelia Huck 	if (!chsc_debug_msg_id)
1689d92a7e1SCornelia Huck 		goto out;
1699d92a7e1SCornelia Huck 	debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
1709d92a7e1SCornelia Huck 	debug_set_level(chsc_debug_msg_id, 2);
1719d92a7e1SCornelia Huck 	chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
1729d92a7e1SCornelia Huck 	if (!chsc_debug_log_id)
1739d92a7e1SCornelia Huck 		goto out;
1749d92a7e1SCornelia Huck 	debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
1759d92a7e1SCornelia Huck 	debug_set_level(chsc_debug_log_id, 2);
1769d92a7e1SCornelia Huck 	return 0;
1779d92a7e1SCornelia Huck out:
1789d92a7e1SCornelia Huck 	if (chsc_debug_msg_id)
1799d92a7e1SCornelia Huck 		debug_unregister(chsc_debug_msg_id);
1809d92a7e1SCornelia Huck 	return -ENOMEM;
1819d92a7e1SCornelia Huck }
1829d92a7e1SCornelia Huck 
1839d92a7e1SCornelia Huck static void chsc_remove_dbfs(void)
1849d92a7e1SCornelia Huck {
1859d92a7e1SCornelia Huck 	debug_unregister(chsc_debug_log_id);
1869d92a7e1SCornelia Huck 	debug_unregister(chsc_debug_msg_id);
1879d92a7e1SCornelia Huck }
1889d92a7e1SCornelia Huck 
1899d92a7e1SCornelia Huck static int __init chsc_init_sch_driver(void)
1909d92a7e1SCornelia Huck {
1919d92a7e1SCornelia Huck 	return css_driver_register(&chsc_subchannel_driver);
1929d92a7e1SCornelia Huck }
1939d92a7e1SCornelia Huck 
1949d92a7e1SCornelia Huck static void chsc_cleanup_sch_driver(void)
1959d92a7e1SCornelia Huck {
1969d92a7e1SCornelia Huck 	css_driver_unregister(&chsc_subchannel_driver);
1979d92a7e1SCornelia Huck }
1989d92a7e1SCornelia Huck 
1999d92a7e1SCornelia Huck static DEFINE_SPINLOCK(chsc_lock);
2009d92a7e1SCornelia Huck 
2019d92a7e1SCornelia Huck static int chsc_subchannel_match_next_free(struct device *dev, void *data)
2029d92a7e1SCornelia Huck {
2039d92a7e1SCornelia Huck 	struct subchannel *sch = to_subchannel(dev);
2049d92a7e1SCornelia Huck 
2059d92a7e1SCornelia Huck 	return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
2069d92a7e1SCornelia Huck }
2079d92a7e1SCornelia Huck 
2089d92a7e1SCornelia Huck static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
2099d92a7e1SCornelia Huck {
2109d92a7e1SCornelia Huck 	struct device *dev;
2119d92a7e1SCornelia Huck 
2129d92a7e1SCornelia Huck 	dev = driver_find_device(&chsc_subchannel_driver.drv,
2139d92a7e1SCornelia Huck 				 sch ? &sch->dev : NULL, NULL,
2149d92a7e1SCornelia Huck 				 chsc_subchannel_match_next_free);
2159d92a7e1SCornelia Huck 	return dev ? to_subchannel(dev) : NULL;
2169d92a7e1SCornelia Huck }
2179d92a7e1SCornelia Huck 
2189d92a7e1SCornelia Huck /**
2199d92a7e1SCornelia Huck  * chsc_async() - try to start a chsc request asynchronously
2209d92a7e1SCornelia Huck  * @chsc_area: request to be started
2219d92a7e1SCornelia Huck  * @request: request structure to associate
2229d92a7e1SCornelia Huck  *
2239d92a7e1SCornelia Huck  * Tries to start a chsc request on one of the existing chsc subchannels.
2249d92a7e1SCornelia Huck  * Returns:
2259d92a7e1SCornelia Huck  *  %0 if the request was performed synchronously
2269d92a7e1SCornelia Huck  *  %-EINPROGRESS if the request was successfully started
2279d92a7e1SCornelia Huck  *  %-EBUSY if all chsc subchannels are busy
2289d92a7e1SCornelia Huck  *  %-ENODEV if no chsc subchannels are available
2299d92a7e1SCornelia Huck  * Context:
2309d92a7e1SCornelia Huck  *  interrupts disabled, chsc_lock held
2319d92a7e1SCornelia Huck  */
2329d92a7e1SCornelia Huck static int chsc_async(struct chsc_async_area *chsc_area,
2339d92a7e1SCornelia Huck 		      struct chsc_request *request)
2349d92a7e1SCornelia Huck {
2359d92a7e1SCornelia Huck 	int cc;
2369d92a7e1SCornelia Huck 	struct chsc_private *private;
2379d92a7e1SCornelia Huck 	struct subchannel *sch = NULL;
2389d92a7e1SCornelia Huck 	int ret = -ENODEV;
2399d92a7e1SCornelia Huck 	char dbf[10];
2409d92a7e1SCornelia Huck 
241d1bf8590SHeiko Carstens 	chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
2429d92a7e1SCornelia Huck 	while ((sch = chsc_get_next_subchannel(sch))) {
2439d92a7e1SCornelia Huck 		spin_lock(sch->lock);
2449d92a7e1SCornelia Huck 		private = sch->private;
2459d92a7e1SCornelia Huck 		if (private->request) {
2469d92a7e1SCornelia Huck 			spin_unlock(sch->lock);
2479d92a7e1SCornelia Huck 			ret = -EBUSY;
2489d92a7e1SCornelia Huck 			continue;
2499d92a7e1SCornelia Huck 		}
2509d92a7e1SCornelia Huck 		chsc_area->header.sid = sch->schid;
2519d92a7e1SCornelia Huck 		CHSC_LOG(2, "schid");
2529d92a7e1SCornelia Huck 		CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
2539d92a7e1SCornelia Huck 		cc = chsc(chsc_area);
2549d92a7e1SCornelia Huck 		sprintf(dbf, "cc:%d", cc);
2559d92a7e1SCornelia Huck 		CHSC_LOG(2, dbf);
2569d92a7e1SCornelia Huck 		switch (cc) {
2579d92a7e1SCornelia Huck 		case 0:
2589d92a7e1SCornelia Huck 			ret = 0;
2599d92a7e1SCornelia Huck 			break;
2609d92a7e1SCornelia Huck 		case 1:
2619d92a7e1SCornelia Huck 			sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
2629d92a7e1SCornelia Huck 			ret = -EINPROGRESS;
2639d92a7e1SCornelia Huck 			private->request = request;
2649d92a7e1SCornelia Huck 			break;
2659d92a7e1SCornelia Huck 		case 2:
2669d92a7e1SCornelia Huck 			ret = -EBUSY;
2679d92a7e1SCornelia Huck 			break;
2689d92a7e1SCornelia Huck 		default:
2699d92a7e1SCornelia Huck 			ret = -ENODEV;
2709d92a7e1SCornelia Huck 		}
2719d92a7e1SCornelia Huck 		spin_unlock(sch->lock);
2729d92a7e1SCornelia Huck 		CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
2739d92a7e1SCornelia Huck 			 sch->schid.ssid, sch->schid.sch_no, cc);
2749d92a7e1SCornelia Huck 		if (ret == -EINPROGRESS)
2759d92a7e1SCornelia Huck 			return -EINPROGRESS;
2769d92a7e1SCornelia Huck 		put_device(&sch->dev);
2779d92a7e1SCornelia Huck 		if (ret == 0)
2789d92a7e1SCornelia Huck 			return 0;
2799d92a7e1SCornelia Huck 	}
2809d92a7e1SCornelia Huck 	return ret;
2819d92a7e1SCornelia Huck }
2829d92a7e1SCornelia Huck 
2839d92a7e1SCornelia Huck static void chsc_log_command(struct chsc_async_area *chsc_area)
2849d92a7e1SCornelia Huck {
2859d92a7e1SCornelia Huck 	char dbf[10];
2869d92a7e1SCornelia Huck 
2879d92a7e1SCornelia Huck 	sprintf(dbf, "CHSC:%x", chsc_area->header.code);
2889d92a7e1SCornelia Huck 	CHSC_LOG(0, dbf);
2899d92a7e1SCornelia Huck 	CHSC_LOG_HEX(0, chsc_area, 32);
2909d92a7e1SCornelia Huck }
2919d92a7e1SCornelia Huck 
2929d92a7e1SCornelia Huck static int chsc_examine_irb(struct chsc_request *request)
2939d92a7e1SCornelia Huck {
2949d92a7e1SCornelia Huck 	int backed_up;
2959d92a7e1SCornelia Huck 
296b2bbb642SJulia Lawall 	if (!(scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND))
2979d92a7e1SCornelia Huck 		return -EIO;
2989d92a7e1SCornelia Huck 	backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
2999d92a7e1SCornelia Huck 	request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
3009d92a7e1SCornelia Huck 	if (scsw_cstat(&request->irb.scsw) == 0)
3019d92a7e1SCornelia Huck 		return 0;
3029d92a7e1SCornelia Huck 	if (!backed_up)
3039d92a7e1SCornelia Huck 		return 0;
3049d92a7e1SCornelia Huck 	if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
3059d92a7e1SCornelia Huck 		return -EIO;
3069d92a7e1SCornelia Huck 	if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
3079d92a7e1SCornelia Huck 		return -EPERM;
3089d92a7e1SCornelia Huck 	if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
3099d92a7e1SCornelia Huck 		return -EAGAIN;
3109d92a7e1SCornelia Huck 	if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
3119d92a7e1SCornelia Huck 		return -EAGAIN;
3129d92a7e1SCornelia Huck 	return -EIO;
3139d92a7e1SCornelia Huck }
3149d92a7e1SCornelia Huck 
3159d92a7e1SCornelia Huck static int chsc_ioctl_start(void __user *user_area)
3169d92a7e1SCornelia Huck {
3179d92a7e1SCornelia Huck 	struct chsc_request *request;
3189d92a7e1SCornelia Huck 	struct chsc_async_area *chsc_area;
3199d92a7e1SCornelia Huck 	int ret;
3209d92a7e1SCornelia Huck 	char dbf[10];
3219d92a7e1SCornelia Huck 
3229d92a7e1SCornelia Huck 	if (!css_general_characteristics.dynio)
3239d92a7e1SCornelia Huck 		/* It makes no sense to try. */
3249d92a7e1SCornelia Huck 		return -EOPNOTSUPP;
3259d92a7e1SCornelia Huck 	chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
3269d92a7e1SCornelia Huck 	if (!chsc_area)
3279d92a7e1SCornelia Huck 		return -ENOMEM;
3289d92a7e1SCornelia Huck 	request = kzalloc(sizeof(*request), GFP_KERNEL);
3299d92a7e1SCornelia Huck 	if (!request) {
3309d92a7e1SCornelia Huck 		ret = -ENOMEM;
3319d92a7e1SCornelia Huck 		goto out_free;
3329d92a7e1SCornelia Huck 	}
3339d92a7e1SCornelia Huck 	init_completion(&request->completion);
3349d92a7e1SCornelia Huck 	if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
3359d92a7e1SCornelia Huck 		ret = -EFAULT;
3369d92a7e1SCornelia Huck 		goto out_free;
3379d92a7e1SCornelia Huck 	}
3389d92a7e1SCornelia Huck 	chsc_log_command(chsc_area);
3399d92a7e1SCornelia Huck 	spin_lock_irq(&chsc_lock);
3409d92a7e1SCornelia Huck 	ret = chsc_async(chsc_area, request);
3419d92a7e1SCornelia Huck 	spin_unlock_irq(&chsc_lock);
3429d92a7e1SCornelia Huck 	if (ret == -EINPROGRESS) {
3439d92a7e1SCornelia Huck 		wait_for_completion(&request->completion);
3449d92a7e1SCornelia Huck 		ret = chsc_examine_irb(request);
3459d92a7e1SCornelia Huck 	}
3469d92a7e1SCornelia Huck 	/* copy area back to user */
3479d92a7e1SCornelia Huck 	if (!ret)
3489d92a7e1SCornelia Huck 		if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
3499d92a7e1SCornelia Huck 			ret = -EFAULT;
3509d92a7e1SCornelia Huck out_free:
3519d92a7e1SCornelia Huck 	sprintf(dbf, "ret:%d", ret);
3529d92a7e1SCornelia Huck 	CHSC_LOG(0, dbf);
3539d92a7e1SCornelia Huck 	kfree(request);
3549d92a7e1SCornelia Huck 	free_page((unsigned long)chsc_area);
3559d92a7e1SCornelia Huck 	return ret;
3569d92a7e1SCornelia Huck }
3579d92a7e1SCornelia Huck 
3589d92a7e1SCornelia Huck static int chsc_ioctl_info_channel_path(void __user *user_cd)
3599d92a7e1SCornelia Huck {
3609d92a7e1SCornelia Huck 	struct chsc_chp_cd *cd;
3619d92a7e1SCornelia Huck 	int ret, ccode;
3629d92a7e1SCornelia Huck 	struct {
3639d92a7e1SCornelia Huck 		struct chsc_header request;
3649d92a7e1SCornelia Huck 		u32 : 2;
3659d92a7e1SCornelia Huck 		u32 m : 1;
3669d92a7e1SCornelia Huck 		u32 : 1;
3679d92a7e1SCornelia Huck 		u32 fmt1 : 4;
3689d92a7e1SCornelia Huck 		u32 cssid : 8;
3699d92a7e1SCornelia Huck 		u32 : 8;
3709d92a7e1SCornelia Huck 		u32 first_chpid : 8;
3719d92a7e1SCornelia Huck 		u32 : 24;
3729d92a7e1SCornelia Huck 		u32 last_chpid : 8;
3739d92a7e1SCornelia Huck 		u32 : 32;
3749d92a7e1SCornelia Huck 		struct chsc_header response;
3759d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 20];
3769d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *scpcd_area;
3779d92a7e1SCornelia Huck 
3789d92a7e1SCornelia Huck 	scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
3799d92a7e1SCornelia Huck 	if (!scpcd_area)
3809d92a7e1SCornelia Huck 		return -ENOMEM;
3819d92a7e1SCornelia Huck 	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
3829d92a7e1SCornelia Huck 	if (!cd) {
3839d92a7e1SCornelia Huck 		ret = -ENOMEM;
3849d92a7e1SCornelia Huck 		goto out_free;
3859d92a7e1SCornelia Huck 	}
3869d92a7e1SCornelia Huck 	if (copy_from_user(cd, user_cd, sizeof(*cd))) {
3879d92a7e1SCornelia Huck 		ret = -EFAULT;
3889d92a7e1SCornelia Huck 		goto out_free;
3899d92a7e1SCornelia Huck 	}
3909d92a7e1SCornelia Huck 	scpcd_area->request.length = 0x0010;
3919d92a7e1SCornelia Huck 	scpcd_area->request.code = 0x0028;
3929d92a7e1SCornelia Huck 	scpcd_area->m = cd->m;
3939d92a7e1SCornelia Huck 	scpcd_area->fmt1 = cd->fmt;
3949d92a7e1SCornelia Huck 	scpcd_area->cssid = cd->chpid.cssid;
3959d92a7e1SCornelia Huck 	scpcd_area->first_chpid = cd->chpid.id;
3969d92a7e1SCornelia Huck 	scpcd_area->last_chpid = cd->chpid.id;
3979d92a7e1SCornelia Huck 
3989d92a7e1SCornelia Huck 	ccode = chsc(scpcd_area);
3999d92a7e1SCornelia Huck 	if (ccode != 0) {
4009d92a7e1SCornelia Huck 		ret = -EIO;
4019d92a7e1SCornelia Huck 		goto out_free;
4029d92a7e1SCornelia Huck 	}
4039d92a7e1SCornelia Huck 	if (scpcd_area->response.code != 0x0001) {
4049d92a7e1SCornelia Huck 		ret = -EIO;
4059d92a7e1SCornelia Huck 		CHSC_MSG(0, "scpcd: response code=%x\n",
4069d92a7e1SCornelia Huck 			 scpcd_area->response.code);
4079d92a7e1SCornelia Huck 		goto out_free;
4089d92a7e1SCornelia Huck 	}
4099d92a7e1SCornelia Huck 	memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
4109d92a7e1SCornelia Huck 	if (copy_to_user(user_cd, cd, sizeof(*cd)))
4119d92a7e1SCornelia Huck 		ret = -EFAULT;
4129d92a7e1SCornelia Huck 	else
4139d92a7e1SCornelia Huck 		ret = 0;
4149d92a7e1SCornelia Huck out_free:
4159d92a7e1SCornelia Huck 	kfree(cd);
4169d92a7e1SCornelia Huck 	free_page((unsigned long)scpcd_area);
4179d92a7e1SCornelia Huck 	return ret;
4189d92a7e1SCornelia Huck }
4199d92a7e1SCornelia Huck 
4209d92a7e1SCornelia Huck static int chsc_ioctl_info_cu(void __user *user_cd)
4219d92a7e1SCornelia Huck {
4229d92a7e1SCornelia Huck 	struct chsc_cu_cd *cd;
4239d92a7e1SCornelia Huck 	int ret, ccode;
4249d92a7e1SCornelia Huck 	struct {
4259d92a7e1SCornelia Huck 		struct chsc_header request;
4269d92a7e1SCornelia Huck 		u32 : 2;
4279d92a7e1SCornelia Huck 		u32 m : 1;
4289d92a7e1SCornelia Huck 		u32 : 1;
4299d92a7e1SCornelia Huck 		u32 fmt1 : 4;
4309d92a7e1SCornelia Huck 		u32 cssid : 8;
4319d92a7e1SCornelia Huck 		u32 : 8;
4329d92a7e1SCornelia Huck 		u32 first_cun : 8;
4339d92a7e1SCornelia Huck 		u32 : 24;
4349d92a7e1SCornelia Huck 		u32 last_cun : 8;
4359d92a7e1SCornelia Huck 		u32 : 32;
4369d92a7e1SCornelia Huck 		struct chsc_header response;
4379d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 20];
4389d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *scucd_area;
4399d92a7e1SCornelia Huck 
4409d92a7e1SCornelia Huck 	scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
4419d92a7e1SCornelia Huck 	if (!scucd_area)
4429d92a7e1SCornelia Huck 		return -ENOMEM;
4439d92a7e1SCornelia Huck 	cd = kzalloc(sizeof(*cd), GFP_KERNEL);
4449d92a7e1SCornelia Huck 	if (!cd) {
4459d92a7e1SCornelia Huck 		ret = -ENOMEM;
4469d92a7e1SCornelia Huck 		goto out_free;
4479d92a7e1SCornelia Huck 	}
4489d92a7e1SCornelia Huck 	if (copy_from_user(cd, user_cd, sizeof(*cd))) {
4499d92a7e1SCornelia Huck 		ret = -EFAULT;
4509d92a7e1SCornelia Huck 		goto out_free;
4519d92a7e1SCornelia Huck 	}
4529d92a7e1SCornelia Huck 	scucd_area->request.length = 0x0010;
4539d92a7e1SCornelia Huck 	scucd_area->request.code = 0x0028;
4549d92a7e1SCornelia Huck 	scucd_area->m = cd->m;
4559d92a7e1SCornelia Huck 	scucd_area->fmt1 = cd->fmt;
4569d92a7e1SCornelia Huck 	scucd_area->cssid = cd->cssid;
4579d92a7e1SCornelia Huck 	scucd_area->first_cun = cd->cun;
4589d92a7e1SCornelia Huck 	scucd_area->last_cun = cd->cun;
4599d92a7e1SCornelia Huck 
4609d92a7e1SCornelia Huck 	ccode = chsc(scucd_area);
4619d92a7e1SCornelia Huck 	if (ccode != 0) {
4629d92a7e1SCornelia Huck 		ret = -EIO;
4639d92a7e1SCornelia Huck 		goto out_free;
4649d92a7e1SCornelia Huck 	}
4659d92a7e1SCornelia Huck 	if (scucd_area->response.code != 0x0001) {
4669d92a7e1SCornelia Huck 		ret = -EIO;
4679d92a7e1SCornelia Huck 		CHSC_MSG(0, "scucd: response code=%x\n",
4689d92a7e1SCornelia Huck 			 scucd_area->response.code);
4699d92a7e1SCornelia Huck 		goto out_free;
4709d92a7e1SCornelia Huck 	}
4719d92a7e1SCornelia Huck 	memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
4729d92a7e1SCornelia Huck 	if (copy_to_user(user_cd, cd, sizeof(*cd)))
4739d92a7e1SCornelia Huck 		ret = -EFAULT;
4749d92a7e1SCornelia Huck 	else
4759d92a7e1SCornelia Huck 		ret = 0;
4769d92a7e1SCornelia Huck out_free:
4779d92a7e1SCornelia Huck 	kfree(cd);
4789d92a7e1SCornelia Huck 	free_page((unsigned long)scucd_area);
4799d92a7e1SCornelia Huck 	return ret;
4809d92a7e1SCornelia Huck }
4819d92a7e1SCornelia Huck 
4829d92a7e1SCornelia Huck static int chsc_ioctl_info_sch_cu(void __user *user_cud)
4839d92a7e1SCornelia Huck {
4849d92a7e1SCornelia Huck 	struct chsc_sch_cud *cud;
4859d92a7e1SCornelia Huck 	int ret, ccode;
4869d92a7e1SCornelia Huck 	struct {
4879d92a7e1SCornelia Huck 		struct chsc_header request;
4889d92a7e1SCornelia Huck 		u32 : 2;
4899d92a7e1SCornelia Huck 		u32 m : 1;
4909d92a7e1SCornelia Huck 		u32 : 5;
4919d92a7e1SCornelia Huck 		u32 fmt1 : 4;
4929d92a7e1SCornelia Huck 		u32 : 2;
4939d92a7e1SCornelia Huck 		u32 ssid : 2;
4949d92a7e1SCornelia Huck 		u32 first_sch : 16;
4959d92a7e1SCornelia Huck 		u32 : 8;
4969d92a7e1SCornelia Huck 		u32 cssid : 8;
4979d92a7e1SCornelia Huck 		u32 last_sch : 16;
4989d92a7e1SCornelia Huck 		u32 : 32;
4999d92a7e1SCornelia Huck 		struct chsc_header response;
5009d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 20];
5019d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *sscud_area;
5029d92a7e1SCornelia Huck 
5039d92a7e1SCornelia Huck 	sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
5049d92a7e1SCornelia Huck 	if (!sscud_area)
5059d92a7e1SCornelia Huck 		return -ENOMEM;
5069d92a7e1SCornelia Huck 	cud = kzalloc(sizeof(*cud), GFP_KERNEL);
5079d92a7e1SCornelia Huck 	if (!cud) {
5089d92a7e1SCornelia Huck 		ret = -ENOMEM;
5099d92a7e1SCornelia Huck 		goto out_free;
5109d92a7e1SCornelia Huck 	}
5119d92a7e1SCornelia Huck 	if (copy_from_user(cud, user_cud, sizeof(*cud))) {
5129d92a7e1SCornelia Huck 		ret = -EFAULT;
5139d92a7e1SCornelia Huck 		goto out_free;
5149d92a7e1SCornelia Huck 	}
5159d92a7e1SCornelia Huck 	sscud_area->request.length = 0x0010;
5169d92a7e1SCornelia Huck 	sscud_area->request.code = 0x0006;
5179d92a7e1SCornelia Huck 	sscud_area->m = cud->schid.m;
5189d92a7e1SCornelia Huck 	sscud_area->fmt1 = cud->fmt;
5199d92a7e1SCornelia Huck 	sscud_area->ssid = cud->schid.ssid;
5209d92a7e1SCornelia Huck 	sscud_area->first_sch = cud->schid.sch_no;
5219d92a7e1SCornelia Huck 	sscud_area->cssid = cud->schid.cssid;
5229d92a7e1SCornelia Huck 	sscud_area->last_sch = cud->schid.sch_no;
5239d92a7e1SCornelia Huck 
5249d92a7e1SCornelia Huck 	ccode = chsc(sscud_area);
5259d92a7e1SCornelia Huck 	if (ccode != 0) {
5269d92a7e1SCornelia Huck 		ret = -EIO;
5279d92a7e1SCornelia Huck 		goto out_free;
5289d92a7e1SCornelia Huck 	}
5299d92a7e1SCornelia Huck 	if (sscud_area->response.code != 0x0001) {
5309d92a7e1SCornelia Huck 		ret = -EIO;
5319d92a7e1SCornelia Huck 		CHSC_MSG(0, "sscud: response code=%x\n",
5329d92a7e1SCornelia Huck 			 sscud_area->response.code);
5339d92a7e1SCornelia Huck 		goto out_free;
5349d92a7e1SCornelia Huck 	}
5359d92a7e1SCornelia Huck 	memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
5369d92a7e1SCornelia Huck 	if (copy_to_user(user_cud, cud, sizeof(*cud)))
5379d92a7e1SCornelia Huck 		ret = -EFAULT;
5389d92a7e1SCornelia Huck 	else
5399d92a7e1SCornelia Huck 		ret = 0;
5409d92a7e1SCornelia Huck out_free:
5419d92a7e1SCornelia Huck 	kfree(cud);
5429d92a7e1SCornelia Huck 	free_page((unsigned long)sscud_area);
5439d92a7e1SCornelia Huck 	return ret;
5449d92a7e1SCornelia Huck }
5459d92a7e1SCornelia Huck 
5469d92a7e1SCornelia Huck static int chsc_ioctl_conf_info(void __user *user_ci)
5479d92a7e1SCornelia Huck {
5489d92a7e1SCornelia Huck 	struct chsc_conf_info *ci;
5499d92a7e1SCornelia Huck 	int ret, ccode;
5509d92a7e1SCornelia Huck 	struct {
5519d92a7e1SCornelia Huck 		struct chsc_header request;
5529d92a7e1SCornelia Huck 		u32 : 2;
5539d92a7e1SCornelia Huck 		u32 m : 1;
5549d92a7e1SCornelia Huck 		u32 : 1;
5559d92a7e1SCornelia Huck 		u32 fmt1 : 4;
5569d92a7e1SCornelia Huck 		u32 cssid : 8;
5579d92a7e1SCornelia Huck 		u32 : 6;
5589d92a7e1SCornelia Huck 		u32 ssid : 2;
5599d92a7e1SCornelia Huck 		u32 : 8;
5609d92a7e1SCornelia Huck 		u64 : 64;
5619d92a7e1SCornelia Huck 		struct chsc_header response;
5629d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 20];
5639d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *sci_area;
5649d92a7e1SCornelia Huck 
5659d92a7e1SCornelia Huck 	sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
5669d92a7e1SCornelia Huck 	if (!sci_area)
5679d92a7e1SCornelia Huck 		return -ENOMEM;
5689d92a7e1SCornelia Huck 	ci = kzalloc(sizeof(*ci), GFP_KERNEL);
5699d92a7e1SCornelia Huck 	if (!ci) {
5709d92a7e1SCornelia Huck 		ret = -ENOMEM;
5719d92a7e1SCornelia Huck 		goto out_free;
5729d92a7e1SCornelia Huck 	}
5739d92a7e1SCornelia Huck 	if (copy_from_user(ci, user_ci, sizeof(*ci))) {
5749d92a7e1SCornelia Huck 		ret = -EFAULT;
5759d92a7e1SCornelia Huck 		goto out_free;
5769d92a7e1SCornelia Huck 	}
5779d92a7e1SCornelia Huck 	sci_area->request.length = 0x0010;
5789d92a7e1SCornelia Huck 	sci_area->request.code = 0x0012;
5799d92a7e1SCornelia Huck 	sci_area->m = ci->id.m;
5809d92a7e1SCornelia Huck 	sci_area->fmt1 = ci->fmt;
5819d92a7e1SCornelia Huck 	sci_area->cssid = ci->id.cssid;
5829d92a7e1SCornelia Huck 	sci_area->ssid = ci->id.ssid;
5839d92a7e1SCornelia Huck 
5849d92a7e1SCornelia Huck 	ccode = chsc(sci_area);
5859d92a7e1SCornelia Huck 	if (ccode != 0) {
5869d92a7e1SCornelia Huck 		ret = -EIO;
5879d92a7e1SCornelia Huck 		goto out_free;
5889d92a7e1SCornelia Huck 	}
5899d92a7e1SCornelia Huck 	if (sci_area->response.code != 0x0001) {
5909d92a7e1SCornelia Huck 		ret = -EIO;
5919d92a7e1SCornelia Huck 		CHSC_MSG(0, "sci: response code=%x\n",
5929d92a7e1SCornelia Huck 			 sci_area->response.code);
5939d92a7e1SCornelia Huck 		goto out_free;
5949d92a7e1SCornelia Huck 	}
5959d92a7e1SCornelia Huck 	memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
5969d92a7e1SCornelia Huck 	if (copy_to_user(user_ci, ci, sizeof(*ci)))
5979d92a7e1SCornelia Huck 		ret = -EFAULT;
5989d92a7e1SCornelia Huck 	else
5999d92a7e1SCornelia Huck 		ret = 0;
6009d92a7e1SCornelia Huck out_free:
6019d92a7e1SCornelia Huck 	kfree(ci);
6029d92a7e1SCornelia Huck 	free_page((unsigned long)sci_area);
6039d92a7e1SCornelia Huck 	return ret;
6049d92a7e1SCornelia Huck }
6059d92a7e1SCornelia Huck 
6069d92a7e1SCornelia Huck static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
6079d92a7e1SCornelia Huck {
6089d92a7e1SCornelia Huck 	struct chsc_comp_list *ccl;
6099d92a7e1SCornelia Huck 	int ret, ccode;
6109d92a7e1SCornelia Huck 	struct {
6119d92a7e1SCornelia Huck 		struct chsc_header request;
6129d92a7e1SCornelia Huck 		u32 ctype : 8;
6139d92a7e1SCornelia Huck 		u32 : 4;
6149d92a7e1SCornelia Huck 		u32 fmt : 4;
6159d92a7e1SCornelia Huck 		u32 : 16;
6169d92a7e1SCornelia Huck 		u64 : 64;
6179d92a7e1SCornelia Huck 		u32 list_parm[2];
6189d92a7e1SCornelia Huck 		u64 : 64;
6199d92a7e1SCornelia Huck 		struct chsc_header response;
6209d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 36];
6219d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *sccl_area;
6229d92a7e1SCornelia Huck 	struct {
6239d92a7e1SCornelia Huck 		u32 m : 1;
6249d92a7e1SCornelia Huck 		u32 : 31;
6259d92a7e1SCornelia Huck 		u32 cssid : 8;
6269d92a7e1SCornelia Huck 		u32 : 16;
6279d92a7e1SCornelia Huck 		u32 chpid : 8;
6289d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *chpid_parm;
6299d92a7e1SCornelia Huck 	struct {
6309d92a7e1SCornelia Huck 		u32 f_cssid : 8;
6319d92a7e1SCornelia Huck 		u32 l_cssid : 8;
6329d92a7e1SCornelia Huck 		u32 : 16;
6339d92a7e1SCornelia Huck 		u32 res;
6349d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *cssids_parm;
6359d92a7e1SCornelia Huck 
6369d92a7e1SCornelia Huck 	sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
6379d92a7e1SCornelia Huck 	if (!sccl_area)
6389d92a7e1SCornelia Huck 		return -ENOMEM;
6399d92a7e1SCornelia Huck 	ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
6409d92a7e1SCornelia Huck 	if (!ccl) {
6419d92a7e1SCornelia Huck 		ret = -ENOMEM;
6429d92a7e1SCornelia Huck 		goto out_free;
6439d92a7e1SCornelia Huck 	}
6449d92a7e1SCornelia Huck 	if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
6459d92a7e1SCornelia Huck 		ret = -EFAULT;
6469d92a7e1SCornelia Huck 		goto out_free;
6479d92a7e1SCornelia Huck 	}
6489d92a7e1SCornelia Huck 	sccl_area->request.length = 0x0020;
6499d92a7e1SCornelia Huck 	sccl_area->request.code = 0x0030;
6509d92a7e1SCornelia Huck 	sccl_area->fmt = ccl->req.fmt;
6519d92a7e1SCornelia Huck 	sccl_area->ctype = ccl->req.ctype;
6529d92a7e1SCornelia Huck 	switch (sccl_area->ctype) {
6539d92a7e1SCornelia Huck 	case CCL_CU_ON_CHP:
6549d92a7e1SCornelia Huck 	case CCL_IOP_CHP:
6559d92a7e1SCornelia Huck 		chpid_parm = (void *)&sccl_area->list_parm;
6569d92a7e1SCornelia Huck 		chpid_parm->m = ccl->req.chpid.m;
6579d92a7e1SCornelia Huck 		chpid_parm->cssid = ccl->req.chpid.chp.cssid;
6589d92a7e1SCornelia Huck 		chpid_parm->chpid = ccl->req.chpid.chp.id;
6599d92a7e1SCornelia Huck 		break;
6609d92a7e1SCornelia Huck 	case CCL_CSS_IMG:
6619d92a7e1SCornelia Huck 	case CCL_CSS_IMG_CONF_CHAR:
6629d92a7e1SCornelia Huck 		cssids_parm = (void *)&sccl_area->list_parm;
6639d92a7e1SCornelia Huck 		cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
6649d92a7e1SCornelia Huck 		cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
6659d92a7e1SCornelia Huck 		break;
6669d92a7e1SCornelia Huck 	}
6679d92a7e1SCornelia Huck 	ccode = chsc(sccl_area);
6689d92a7e1SCornelia Huck 	if (ccode != 0) {
6699d92a7e1SCornelia Huck 		ret = -EIO;
6709d92a7e1SCornelia Huck 		goto out_free;
6719d92a7e1SCornelia Huck 	}
6729d92a7e1SCornelia Huck 	if (sccl_area->response.code != 0x0001) {
6739d92a7e1SCornelia Huck 		ret = -EIO;
6749d92a7e1SCornelia Huck 		CHSC_MSG(0, "sccl: response code=%x\n",
6759d92a7e1SCornelia Huck 			 sccl_area->response.code);
6769d92a7e1SCornelia Huck 		goto out_free;
6779d92a7e1SCornelia Huck 	}
6789d92a7e1SCornelia Huck 	memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
6799d92a7e1SCornelia Huck 	if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
6809d92a7e1SCornelia Huck 		ret = -EFAULT;
6819d92a7e1SCornelia Huck 	else
6829d92a7e1SCornelia Huck 		ret = 0;
6839d92a7e1SCornelia Huck out_free:
6849d92a7e1SCornelia Huck 	kfree(ccl);
6859d92a7e1SCornelia Huck 	free_page((unsigned long)sccl_area);
6869d92a7e1SCornelia Huck 	return ret;
6879d92a7e1SCornelia Huck }
6889d92a7e1SCornelia Huck 
6899d92a7e1SCornelia Huck static int chsc_ioctl_chpd(void __user *user_chpd)
6909d92a7e1SCornelia Huck {
6919d92a7e1SCornelia Huck 	struct chsc_cpd_info *chpd;
6929d92a7e1SCornelia Huck 	int ret;
6939d92a7e1SCornelia Huck 
6949d92a7e1SCornelia Huck 	chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
6959d92a7e1SCornelia Huck 	if (!chpd)
6969d92a7e1SCornelia Huck 		return -ENOMEM;
6979d92a7e1SCornelia Huck 	if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
6989d92a7e1SCornelia Huck 		ret = -EFAULT;
6999d92a7e1SCornelia Huck 		goto out_free;
7009d92a7e1SCornelia Huck 	}
7019d92a7e1SCornelia Huck 	ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
7029d92a7e1SCornelia Huck 					       chpd->rfmt, chpd->c, chpd->m,
7039d92a7e1SCornelia Huck 					       &chpd->chpdb);
7049d92a7e1SCornelia Huck 	if (ret)
7059d92a7e1SCornelia Huck 		goto out_free;
7069d92a7e1SCornelia Huck 	if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
7079d92a7e1SCornelia Huck 		ret = -EFAULT;
7089d92a7e1SCornelia Huck out_free:
7099d92a7e1SCornelia Huck 	kfree(chpd);
7109d92a7e1SCornelia Huck 	return ret;
7119d92a7e1SCornelia Huck }
7129d92a7e1SCornelia Huck 
7139d92a7e1SCornelia Huck static int chsc_ioctl_dcal(void __user *user_dcal)
7149d92a7e1SCornelia Huck {
7159d92a7e1SCornelia Huck 	struct chsc_dcal *dcal;
7169d92a7e1SCornelia Huck 	int ret, ccode;
7179d92a7e1SCornelia Huck 	struct {
7189d92a7e1SCornelia Huck 		struct chsc_header request;
7199d92a7e1SCornelia Huck 		u32 atype : 8;
7209d92a7e1SCornelia Huck 		u32 : 4;
7219d92a7e1SCornelia Huck 		u32 fmt : 4;
7229d92a7e1SCornelia Huck 		u32 : 16;
7239d92a7e1SCornelia Huck 		u32 res0[2];
7249d92a7e1SCornelia Huck 		u32 list_parm[2];
7259d92a7e1SCornelia Huck 		u32 res1[2];
7269d92a7e1SCornelia Huck 		struct chsc_header response;
7279d92a7e1SCornelia Huck 		u8 data[PAGE_SIZE - 36];
7289d92a7e1SCornelia Huck 	} __attribute__ ((packed)) *sdcal_area;
7299d92a7e1SCornelia Huck 
7309d92a7e1SCornelia Huck 	sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
7319d92a7e1SCornelia Huck 	if (!sdcal_area)
7329d92a7e1SCornelia Huck 		return -ENOMEM;
7339d92a7e1SCornelia Huck 	dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
7349d92a7e1SCornelia Huck 	if (!dcal) {
7359d92a7e1SCornelia Huck 		ret = -ENOMEM;
7369d92a7e1SCornelia Huck 		goto out_free;
7379d92a7e1SCornelia Huck 	}
7389d92a7e1SCornelia Huck 	if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
7399d92a7e1SCornelia Huck 		ret = -EFAULT;
7409d92a7e1SCornelia Huck 		goto out_free;
7419d92a7e1SCornelia Huck 	}
7429d92a7e1SCornelia Huck 	sdcal_area->request.length = 0x0020;
7439d92a7e1SCornelia Huck 	sdcal_area->request.code = 0x0034;
7449d92a7e1SCornelia Huck 	sdcal_area->atype = dcal->req.atype;
7459d92a7e1SCornelia Huck 	sdcal_area->fmt = dcal->req.fmt;
7469d92a7e1SCornelia Huck 	memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
7479d92a7e1SCornelia Huck 	       sizeof(sdcal_area->list_parm));
7489d92a7e1SCornelia Huck 
7499d92a7e1SCornelia Huck 	ccode = chsc(sdcal_area);
7509d92a7e1SCornelia Huck 	if (ccode != 0) {
7519d92a7e1SCornelia Huck 		ret = -EIO;
7529d92a7e1SCornelia Huck 		goto out_free;
7539d92a7e1SCornelia Huck 	}
7549d92a7e1SCornelia Huck 	if (sdcal_area->response.code != 0x0001) {
7559d92a7e1SCornelia Huck 		ret = -EIO;
7569d92a7e1SCornelia Huck 		CHSC_MSG(0, "sdcal: response code=%x\n",
7579d92a7e1SCornelia Huck 			 sdcal_area->response.code);
7589d92a7e1SCornelia Huck 		goto out_free;
7599d92a7e1SCornelia Huck 	}
7609d92a7e1SCornelia Huck 	memcpy(&dcal->sdcal, &sdcal_area->response,
7619d92a7e1SCornelia Huck 	       sdcal_area->response.length);
7629d92a7e1SCornelia Huck 	if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
7639d92a7e1SCornelia Huck 		ret = -EFAULT;
7649d92a7e1SCornelia Huck 	else
7659d92a7e1SCornelia Huck 		ret = 0;
7669d92a7e1SCornelia Huck out_free:
7679d92a7e1SCornelia Huck 	kfree(dcal);
7689d92a7e1SCornelia Huck 	free_page((unsigned long)sdcal_area);
7699d92a7e1SCornelia Huck 	return ret;
7709d92a7e1SCornelia Huck }
7719d92a7e1SCornelia Huck 
7729d92a7e1SCornelia Huck static long chsc_ioctl(struct file *filp, unsigned int cmd,
7739d92a7e1SCornelia Huck 		       unsigned long arg)
7749d92a7e1SCornelia Huck {
77544ee6a85SHeiko Carstens 	void __user *argp;
77644ee6a85SHeiko Carstens 
7779d92a7e1SCornelia Huck 	CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
77844ee6a85SHeiko Carstens 	if (is_compat_task())
77944ee6a85SHeiko Carstens 		argp = compat_ptr(arg);
78044ee6a85SHeiko Carstens 	else
78144ee6a85SHeiko Carstens 		argp = (void __user *)arg;
7829d92a7e1SCornelia Huck 	switch (cmd) {
7839d92a7e1SCornelia Huck 	case CHSC_START:
78444ee6a85SHeiko Carstens 		return chsc_ioctl_start(argp);
7859d92a7e1SCornelia Huck 	case CHSC_INFO_CHANNEL_PATH:
78644ee6a85SHeiko Carstens 		return chsc_ioctl_info_channel_path(argp);
7879d92a7e1SCornelia Huck 	case CHSC_INFO_CU:
78844ee6a85SHeiko Carstens 		return chsc_ioctl_info_cu(argp);
7899d92a7e1SCornelia Huck 	case CHSC_INFO_SCH_CU:
79044ee6a85SHeiko Carstens 		return chsc_ioctl_info_sch_cu(argp);
7919d92a7e1SCornelia Huck 	case CHSC_INFO_CI:
79244ee6a85SHeiko Carstens 		return chsc_ioctl_conf_info(argp);
7939d92a7e1SCornelia Huck 	case CHSC_INFO_CCL:
79444ee6a85SHeiko Carstens 		return chsc_ioctl_conf_comp_list(argp);
7959d92a7e1SCornelia Huck 	case CHSC_INFO_CPD:
79644ee6a85SHeiko Carstens 		return chsc_ioctl_chpd(argp);
7979d92a7e1SCornelia Huck 	case CHSC_INFO_DCAL:
79844ee6a85SHeiko Carstens 		return chsc_ioctl_dcal(argp);
7999d92a7e1SCornelia Huck 	default: /* unknown ioctl number */
8009d92a7e1SCornelia Huck 		return -ENOIOCTLCMD;
8019d92a7e1SCornelia Huck 	}
8029d92a7e1SCornelia Huck }
8039d92a7e1SCornelia Huck 
8049d92a7e1SCornelia Huck static const struct file_operations chsc_fops = {
8059d92a7e1SCornelia Huck 	.owner = THIS_MODULE,
8069d92a7e1SCornelia Huck 	.unlocked_ioctl = chsc_ioctl,
8079d92a7e1SCornelia Huck 	.compat_ioctl = chsc_ioctl,
8089d92a7e1SCornelia Huck };
8099d92a7e1SCornelia Huck 
8109d92a7e1SCornelia Huck static struct miscdevice chsc_misc_device = {
8119d92a7e1SCornelia Huck 	.minor = MISC_DYNAMIC_MINOR,
8129d92a7e1SCornelia Huck 	.name = "chsc",
8139d92a7e1SCornelia Huck 	.fops = &chsc_fops,
8149d92a7e1SCornelia Huck };
8159d92a7e1SCornelia Huck 
8169d92a7e1SCornelia Huck static int __init chsc_misc_init(void)
8179d92a7e1SCornelia Huck {
8189d92a7e1SCornelia Huck 	return misc_register(&chsc_misc_device);
8199d92a7e1SCornelia Huck }
8209d92a7e1SCornelia Huck 
8219d92a7e1SCornelia Huck static void chsc_misc_cleanup(void)
8229d92a7e1SCornelia Huck {
8239d92a7e1SCornelia Huck 	misc_deregister(&chsc_misc_device);
8249d92a7e1SCornelia Huck }
8259d92a7e1SCornelia Huck 
8269d92a7e1SCornelia Huck static int __init chsc_sch_init(void)
8279d92a7e1SCornelia Huck {
8289d92a7e1SCornelia Huck 	int ret;
8299d92a7e1SCornelia Huck 
8309d92a7e1SCornelia Huck 	ret = chsc_init_dbfs();
8319d92a7e1SCornelia Huck 	if (ret)
8329d92a7e1SCornelia Huck 		return ret;
8339d92a7e1SCornelia Huck 	isc_register(CHSC_SCH_ISC);
8349d92a7e1SCornelia Huck 	ret = chsc_init_sch_driver();
8359d92a7e1SCornelia Huck 	if (ret)
8369d92a7e1SCornelia Huck 		goto out_dbf;
8379d92a7e1SCornelia Huck 	ret = chsc_misc_init();
8389d92a7e1SCornelia Huck 	if (ret)
8399d92a7e1SCornelia Huck 		goto out_driver;
8409d92a7e1SCornelia Huck 	return ret;
8419d92a7e1SCornelia Huck out_driver:
8429d92a7e1SCornelia Huck 	chsc_cleanup_sch_driver();
8439d92a7e1SCornelia Huck out_dbf:
8449d92a7e1SCornelia Huck 	isc_unregister(CHSC_SCH_ISC);
8459d92a7e1SCornelia Huck 	chsc_remove_dbfs();
8469d92a7e1SCornelia Huck 	return ret;
8479d92a7e1SCornelia Huck }
8489d92a7e1SCornelia Huck 
8499d92a7e1SCornelia Huck static void __exit chsc_sch_exit(void)
8509d92a7e1SCornelia Huck {
8519d92a7e1SCornelia Huck 	chsc_misc_cleanup();
8529d92a7e1SCornelia Huck 	chsc_cleanup_sch_driver();
8539d92a7e1SCornelia Huck 	isc_unregister(CHSC_SCH_ISC);
8549d92a7e1SCornelia Huck 	chsc_remove_dbfs();
8559d92a7e1SCornelia Huck }
8569d92a7e1SCornelia Huck 
8579d92a7e1SCornelia Huck module_init(chsc_sch_init);
8589d92a7e1SCornelia Huck module_exit(chsc_sch_exit);
859