^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) * Driver for s390 chsc subchannels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright IBM Corp. 2008, 2011
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/compat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/cio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <asm/chsc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <asm/isc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "cio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "cio_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "css.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "chsc_sch.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "ioasm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static debug_info_t *chsc_debug_msg_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static debug_info_t *chsc_debug_log_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static struct chsc_request *on_close_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static struct chsc_async_area *on_close_chsc_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static DEFINE_MUTEX(on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define CHSC_MSG(imp, args...) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) debug_sprintf_event(chsc_debug_msg_id, imp , ##args); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define CHSC_LOG(imp, txt) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) debug_text_event(chsc_debug_log_id, imp , txt); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static void CHSC_LOG_HEX(int level, void *data, int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) debug_event(chsc_debug_log_id, level, data, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_AUTHOR("IBM Corporation");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) MODULE_DESCRIPTION("driver for s390 chsc subchannels");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static void chsc_subchannel_irq(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct chsc_private *private = dev_get_drvdata(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct chsc_request *request = private->request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct irb *irb = this_cpu_ptr(&cio_irb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) CHSC_LOG(4, "irb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) CHSC_LOG_HEX(4, irb, sizeof(*irb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) inc_irq_stat(IRQIO_CSC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) /* Copy irb to provided request and set done. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (!request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) CHSC_MSG(0, "Interrupt on sch 0.%x.%04x with no request\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) sch->schid.ssid, sch->schid.sch_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) private->request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) memcpy(&request->irb, irb, sizeof(*irb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) cio_update_schib(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) complete(&request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) put_device(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static int chsc_subchannel_probe(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct chsc_private *private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) CHSC_MSG(6, "Detected chsc subchannel 0.%x.%04x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) sch->schid.ssid, sch->schid.sch_no);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sch->isc = CHSC_SCH_ISC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) private = kzalloc(sizeof(*private), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (!private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) dev_set_drvdata(&sch->dev, private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) CHSC_MSG(0, "Failed to enable 0.%x.%04x: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) sch->schid.ssid, sch->schid.sch_no, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) dev_set_drvdata(&sch->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) kfree(private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (dev_get_uevent_suppress(&sch->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) dev_set_uevent_suppress(&sch->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static int chsc_subchannel_remove(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct chsc_private *private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) cio_disable_subchannel(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) private = dev_get_drvdata(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev_set_drvdata(&sch->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (private->request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) complete(&private->request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) put_device(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) kfree(private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static void chsc_subchannel_shutdown(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) cio_disable_subchannel(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int chsc_subchannel_prepare(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct schib schib;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * Don't allow suspend while the subchannel is not idle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) * since we don't have a way to clear the subchannel and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * cannot disable it with a request running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) cc = stsch(sch->schid, &schib);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) if (!cc && scsw_stctl(&schib.scsw))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int chsc_subchannel_freeze(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return cio_disable_subchannel(sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static int chsc_subchannel_restore(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return cio_enable_subchannel(sch, (u32)(unsigned long)sch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static struct css_device_id chsc_subchannel_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) { .match_flags = 0x1, .type =SUBCHANNEL_TYPE_CHSC, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) { /* end of list */ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) MODULE_DEVICE_TABLE(css, chsc_subchannel_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static struct css_driver chsc_subchannel_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) .drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .name = "chsc_subchannel",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .subchannel_type = chsc_subchannel_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .irq = chsc_subchannel_irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .probe = chsc_subchannel_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .remove = chsc_subchannel_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .shutdown = chsc_subchannel_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .prepare = chsc_subchannel_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) .freeze = chsc_subchannel_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .thaw = chsc_subchannel_restore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .restore = chsc_subchannel_restore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static int __init chsc_init_dbfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) chsc_debug_msg_id = debug_register("chsc_msg", 8, 1, 4 * sizeof(long));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (!chsc_debug_msg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) debug_register_view(chsc_debug_msg_id, &debug_sprintf_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) debug_set_level(chsc_debug_msg_id, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) chsc_debug_log_id = debug_register("chsc_log", 16, 1, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (!chsc_debug_log_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) debug_register_view(chsc_debug_log_id, &debug_hex_ascii_view);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) debug_set_level(chsc_debug_log_id, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) debug_unregister(chsc_debug_msg_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) static void chsc_remove_dbfs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) debug_unregister(chsc_debug_log_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) debug_unregister(chsc_debug_msg_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static int __init chsc_init_sch_driver(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return css_driver_register(&chsc_subchannel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static void chsc_cleanup_sch_driver(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) css_driver_unregister(&chsc_subchannel_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static DEFINE_SPINLOCK(chsc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static int chsc_subchannel_match_next_free(struct device *dev, const void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct subchannel *sch = to_subchannel(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return sch->schib.pmcw.ena && !scsw_fctl(&sch->schib.scsw);
^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) static struct subchannel *chsc_get_next_subchannel(struct subchannel *sch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) dev = driver_find_device(&chsc_subchannel_driver.drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) sch ? &sch->dev : NULL, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) chsc_subchannel_match_next_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return dev ? to_subchannel(dev) : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * chsc_async() - try to start a chsc request asynchronously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * @chsc_area: request to be started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * @request: request structure to associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * Tries to start a chsc request on one of the existing chsc subchannels.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * %0 if the request was performed synchronously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * %-EINPROGRESS if the request was successfully started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * %-EBUSY if all chsc subchannels are busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * %-ENODEV if no chsc subchannels are available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Context:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * interrupts disabled, chsc_lock held
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int chsc_async(struct chsc_async_area *chsc_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct chsc_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) int cc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct chsc_private *private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct subchannel *sch = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) char dbf[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) chsc_area->header.key = PAGE_DEFAULT_KEY >> 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) while ((sch = chsc_get_next_subchannel(sch))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) spin_lock(sch->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) private = dev_get_drvdata(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (private->request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) spin_unlock(sch->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) chsc_area->header.sid = sch->schid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) CHSC_LOG(2, "schid");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) CHSC_LOG_HEX(2, &sch->schid, sizeof(sch->schid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) cc = chsc(chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) snprintf(dbf, sizeof(dbf), "cc:%d", cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) CHSC_LOG(2, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) switch (cc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sch->schib.scsw.cmd.fctl |= SCSW_FCTL_START_FUNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) ret = -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) private->request = request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) case 2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) spin_unlock(sch->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) CHSC_MSG(2, "chsc on 0.%x.%04x returned cc=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) sch->schid.ssid, sch->schid.sch_no, cc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (ret == -EINPROGRESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return -EINPROGRESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) put_device(&sch->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static void chsc_log_command(void *chsc_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) char dbf[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) snprintf(dbf, sizeof(dbf), "CHSC:%x", ((uint16_t *)chsc_area)[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) CHSC_LOG(0, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) CHSC_LOG_HEX(0, chsc_area, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static int chsc_examine_irb(struct chsc_request *request)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) int backed_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (!(scsw_stctl(&request->irb.scsw) & SCSW_STCTL_STATUS_PEND))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) backed_up = scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHAIN_CHECK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) request->irb.scsw.cmd.cstat &= ~SCHN_STAT_CHAIN_CHECK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (scsw_cstat(&request->irb.scsw) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (!backed_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROG_CHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_PROT_CHECK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_DATA_CHK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (scsw_cstat(&request->irb.scsw) & SCHN_STAT_CHN_CTRL_CHK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) static int chsc_ioctl_start(void __user *user_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct chsc_request *request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) struct chsc_async_area *chsc_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) char dbf[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (!css_general_characteristics.dynio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) /* It makes no sense to try. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (!chsc_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) request = kzalloc(sizeof(*request), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) if (!request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) init_completion(&request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) chsc_log_command(chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) spin_lock_irq(&chsc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) ret = chsc_async(chsc_area, request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) spin_unlock_irq(&chsc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (ret == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) wait_for_completion(&request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) ret = chsc_examine_irb(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /* copy area back to user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) snprintf(dbf, sizeof(dbf), "ret:%d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) CHSC_LOG(0, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) kfree(request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) free_page((unsigned long)chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) static int chsc_ioctl_on_close_set(void __user *user_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) char dbf[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) mutex_lock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (on_close_chsc_area) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ret = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) on_close_request = kzalloc(sizeof(*on_close_request), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!on_close_request) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) on_close_chsc_area = (void *)get_zeroed_page(GFP_DMA | GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (!on_close_chsc_area) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) goto out_free_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (copy_from_user(on_close_chsc_area, user_area, PAGE_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) goto out_free_chsc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) out_free_chsc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) free_page((unsigned long)on_close_chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) on_close_chsc_area = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) out_free_request:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) kfree(on_close_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) on_close_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) mutex_unlock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) snprintf(dbf, sizeof(dbf), "ocsret:%d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) CHSC_LOG(0, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static int chsc_ioctl_on_close_remove(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) char dbf[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) mutex_lock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (!on_close_chsc_area) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ret = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) free_page((unsigned long)on_close_chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) on_close_chsc_area = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) kfree(on_close_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) on_close_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) mutex_unlock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) snprintf(dbf, sizeof(dbf), "ocrret:%d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) CHSC_LOG(0, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static int chsc_ioctl_start_sync(void __user *user_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct chsc_sync_area *chsc_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) chsc_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (!chsc_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (copy_from_user(chsc_area, user_area, PAGE_SIZE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (chsc_area->header.code & 0x4000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) chsc_log_command(chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ccode = chsc(chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (copy_to_user(user_area, chsc_area, PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) free_page((unsigned long)chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) static int chsc_ioctl_info_channel_path(void __user *user_cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct chsc_chp_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) u32 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) u32 m : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) u32 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) u32 fmt1 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) u32 cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) u32 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) u32 first_chpid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) u32 : 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) u32 last_chpid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) u32 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) u8 data[PAGE_SIZE - 20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) } __attribute__ ((packed)) *scpcd_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) scpcd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!scpcd_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) cd = kzalloc(sizeof(*cd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!cd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) if (copy_from_user(cd, user_cd, sizeof(*cd))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) scpcd_area->request.length = 0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) scpcd_area->request.code = 0x0028;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) scpcd_area->m = cd->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) scpcd_area->fmt1 = cd->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) scpcd_area->cssid = cd->chpid.cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) scpcd_area->first_chpid = cd->chpid.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) scpcd_area->last_chpid = cd->chpid.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ccode = chsc(scpcd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (scpcd_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) CHSC_MSG(0, "scpcd: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) scpcd_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) memcpy(&cd->cpcb, &scpcd_area->response, scpcd_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) if (copy_to_user(user_cd, cd, sizeof(*cd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) kfree(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) free_page((unsigned long)scpcd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static int chsc_ioctl_info_cu(void __user *user_cd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct chsc_cu_cd *cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) u32 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) u32 m : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) u32 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) u32 fmt1 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) u32 cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) u32 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) u32 first_cun : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) u32 : 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) u32 last_cun : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) u32 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) u8 data[PAGE_SIZE - 20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) } __attribute__ ((packed)) *scucd_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) scucd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (!scucd_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) cd = kzalloc(sizeof(*cd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (!cd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (copy_from_user(cd, user_cd, sizeof(*cd))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) scucd_area->request.length = 0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) scucd_area->request.code = 0x0026;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) scucd_area->m = cd->m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) scucd_area->fmt1 = cd->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) scucd_area->cssid = cd->cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) scucd_area->first_cun = cd->cun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) scucd_area->last_cun = cd->cun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) ccode = chsc(scucd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (scucd_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) CHSC_MSG(0, "scucd: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) scucd_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) memcpy(&cd->cucb, &scucd_area->response, scucd_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (copy_to_user(user_cd, cd, sizeof(*cd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) kfree(cd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) free_page((unsigned long)scucd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static int chsc_ioctl_info_sch_cu(void __user *user_cud)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct chsc_sch_cud *cud;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) u32 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) u32 m : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) u32 : 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) u32 fmt1 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) u32 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) u32 ssid : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) u32 first_sch : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) u32 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) u32 cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) u32 last_sch : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) u32 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) u8 data[PAGE_SIZE - 20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) } __attribute__ ((packed)) *sscud_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) sscud_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) if (!sscud_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) cud = kzalloc(sizeof(*cud), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) if (!cud) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (copy_from_user(cud, user_cud, sizeof(*cud))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) sscud_area->request.length = 0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) sscud_area->request.code = 0x0006;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) sscud_area->m = cud->schid.m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) sscud_area->fmt1 = cud->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) sscud_area->ssid = cud->schid.ssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) sscud_area->first_sch = cud->schid.sch_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) sscud_area->cssid = cud->schid.cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) sscud_area->last_sch = cud->schid.sch_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) ccode = chsc(sscud_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (sscud_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) CHSC_MSG(0, "sscud: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) sscud_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) memcpy(&cud->scub, &sscud_area->response, sscud_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (copy_to_user(user_cud, cud, sizeof(*cud)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) kfree(cud);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) free_page((unsigned long)sscud_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return ret;
^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) static int chsc_ioctl_conf_info(void __user *user_ci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) struct chsc_conf_info *ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) u32 : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) u32 m : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) u32 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) u32 fmt1 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) u32 cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) u32 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u32 ssid : 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) u32 : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) u64 : 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) u8 data[PAGE_SIZE - 20];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) } __attribute__ ((packed)) *sci_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) sci_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) if (!sci_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) ci = kzalloc(sizeof(*ci), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) if (!ci) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) if (copy_from_user(ci, user_ci, sizeof(*ci))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) sci_area->request.length = 0x0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) sci_area->request.code = 0x0012;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) sci_area->m = ci->id.m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) sci_area->fmt1 = ci->fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) sci_area->cssid = ci->id.cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) sci_area->ssid = ci->id.ssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) ccode = chsc(sci_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (sci_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) CHSC_MSG(0, "sci: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) sci_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) memcpy(&ci->scid, &sci_area->response, sci_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) if (copy_to_user(user_ci, ci, sizeof(*ci)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) kfree(ci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) free_page((unsigned long)sci_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static int chsc_ioctl_conf_comp_list(void __user *user_ccl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) struct chsc_comp_list *ccl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) u32 ctype : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) u32 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) u32 fmt : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) u32 : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) u64 : 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) u32 list_parm[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) u64 : 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) u8 data[PAGE_SIZE - 36];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) } __attribute__ ((packed)) *sccl_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) u32 m : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) u32 : 31;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) u32 cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) u32 : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) u32 chpid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) } __attribute__ ((packed)) *chpid_parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) u32 f_cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) u32 l_cssid : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) u32 : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) u32 res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) } __attribute__ ((packed)) *cssids_parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) sccl_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!sccl_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ccl = kzalloc(sizeof(*ccl), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (!ccl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (copy_from_user(ccl, user_ccl, sizeof(*ccl))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) sccl_area->request.length = 0x0020;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) sccl_area->request.code = 0x0030;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) sccl_area->fmt = ccl->req.fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) sccl_area->ctype = ccl->req.ctype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) switch (sccl_area->ctype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) case CCL_CU_ON_CHP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) case CCL_IOP_CHP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) chpid_parm = (void *)&sccl_area->list_parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) chpid_parm->m = ccl->req.chpid.m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) chpid_parm->cssid = ccl->req.chpid.chp.cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) chpid_parm->chpid = ccl->req.chpid.chp.id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) case CCL_CSS_IMG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) case CCL_CSS_IMG_CONF_CHAR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) cssids_parm = (void *)&sccl_area->list_parm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) cssids_parm->f_cssid = ccl->req.cssids.f_cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) cssids_parm->l_cssid = ccl->req.cssids.l_cssid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) ccode = chsc(sccl_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (sccl_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) CHSC_MSG(0, "sccl: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) sccl_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) memcpy(&ccl->sccl, &sccl_area->response, sccl_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) if (copy_to_user(user_ccl, ccl, sizeof(*ccl)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) kfree(ccl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) free_page((unsigned long)sccl_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) static int chsc_ioctl_chpd(void __user *user_chpd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct chsc_scpd *scpd_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct chsc_cpd_info *chpd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) chpd = kzalloc(sizeof(*chpd), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) scpd_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) if (!scpd_area || !chpd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) if (copy_from_user(chpd, user_chpd, sizeof(*chpd))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) ret = chsc_determine_channel_path_desc(chpd->chpid, chpd->fmt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) chpd->rfmt, chpd->c, chpd->m,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) scpd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) memcpy(&chpd->chpdb, &scpd_area->response, scpd_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) if (copy_to_user(user_chpd, chpd, sizeof(*chpd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) kfree(chpd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) free_page((unsigned long)scpd_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) static int chsc_ioctl_dcal(void __user *user_dcal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct chsc_dcal *dcal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) int ret, ccode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) struct chsc_header request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) u32 atype : 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) u32 : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) u32 fmt : 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) u32 : 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) u32 res0[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) u32 list_parm[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) u32 res1[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) struct chsc_header response;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) u8 data[PAGE_SIZE - 36];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) } __attribute__ ((packed)) *sdcal_area;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) sdcal_area = (void *)get_zeroed_page(GFP_KERNEL | GFP_DMA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (!sdcal_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) dcal = kzalloc(sizeof(*dcal), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (!dcal) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (copy_from_user(dcal, user_dcal, sizeof(*dcal))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) sdcal_area->request.length = 0x0020;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) sdcal_area->request.code = 0x0034;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) sdcal_area->atype = dcal->req.atype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) sdcal_area->fmt = dcal->req.fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) memcpy(&sdcal_area->list_parm, &dcal->req.list_parm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) sizeof(sdcal_area->list_parm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) ccode = chsc(sdcal_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) if (ccode != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (sdcal_area->response.code != 0x0001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) CHSC_MSG(0, "sdcal: response code=%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) sdcal_area->response.code);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) memcpy(&dcal->sdcal, &sdcal_area->response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) sdcal_area->response.length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) if (copy_to_user(user_dcal, dcal, sizeof(*dcal)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) kfree(dcal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) free_page((unsigned long)sdcal_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) static long chsc_ioctl(struct file *filp, unsigned int cmd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) void __user *argp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) CHSC_MSG(2, "chsc_ioctl called, cmd=%x\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) if (is_compat_task())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) argp = compat_ptr(arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) argp = (void __user *)arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) case CHSC_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return chsc_ioctl_start(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) case CHSC_START_SYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) return chsc_ioctl_start_sync(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) case CHSC_INFO_CHANNEL_PATH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) return chsc_ioctl_info_channel_path(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) case CHSC_INFO_CU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return chsc_ioctl_info_cu(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) case CHSC_INFO_SCH_CU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return chsc_ioctl_info_sch_cu(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) case CHSC_INFO_CI:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return chsc_ioctl_conf_info(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) case CHSC_INFO_CCL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) return chsc_ioctl_conf_comp_list(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) case CHSC_INFO_CPD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) return chsc_ioctl_chpd(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) case CHSC_INFO_DCAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return chsc_ioctl_dcal(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) case CHSC_ON_CLOSE_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) return chsc_ioctl_on_close_set(argp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) case CHSC_ON_CLOSE_REMOVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return chsc_ioctl_on_close_remove();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) default: /* unknown ioctl number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return -ENOIOCTLCMD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) static atomic_t chsc_ready_for_use = ATOMIC_INIT(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) static int chsc_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (!atomic_dec_and_test(&chsc_ready_for_use)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) atomic_inc(&chsc_ready_for_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) return nonseekable_open(inode, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) static int chsc_release(struct inode *inode, struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) char dbf[13];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) mutex_lock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (!on_close_chsc_area)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) init_completion(&on_close_request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) CHSC_LOG(0, "on_close");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) chsc_log_command(on_close_chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) spin_lock_irq(&chsc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) ret = chsc_async(on_close_chsc_area, on_close_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) spin_unlock_irq(&chsc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (ret == -EINPROGRESS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) wait_for_completion(&on_close_request->completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ret = chsc_examine_irb(on_close_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) snprintf(dbf, sizeof(dbf), "relret:%d", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) CHSC_LOG(0, dbf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) free_page((unsigned long)on_close_chsc_area);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) on_close_chsc_area = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) kfree(on_close_request);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) on_close_request = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) mutex_unlock(&on_close_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) atomic_inc(&chsc_ready_for_use);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) static const struct file_operations chsc_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) .open = chsc_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) .release = chsc_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) .unlocked_ioctl = chsc_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) .compat_ioctl = chsc_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) .llseek = no_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) static struct miscdevice chsc_misc_device = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) .minor = MISC_DYNAMIC_MINOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) .name = "chsc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) .fops = &chsc_fops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) static int __init chsc_misc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) return misc_register(&chsc_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) static void chsc_misc_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) misc_deregister(&chsc_misc_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) static int __init chsc_sch_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) ret = chsc_init_dbfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) isc_register(CHSC_SCH_ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) ret = chsc_init_sch_driver();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) goto out_dbf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) ret = chsc_misc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) goto out_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) out_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) chsc_cleanup_sch_driver();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) out_dbf:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) isc_unregister(CHSC_SCH_ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) chsc_remove_dbfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static void __exit chsc_sch_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) chsc_misc_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) chsc_cleanup_sch_driver();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) isc_unregister(CHSC_SCH_ISC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) chsc_remove_dbfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) module_init(chsc_sch_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) module_exit(chsc_sch_exit);