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