11 #define KMSG_COMPONENT "vmur"
12 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
15 #include <linux/slab.h>
16 #include <linux/module.h>
18 #include <asm/uaccess.h>
21 #include <asm/debug.h>
41 static char ur_banner[] =
"z/VM virtual unit record device driver";
47 static dev_t ur_first_dev_maj_min;
48 static struct class *vmur_class;
74 .set_online = ur_set_online,
75 .set_offline = ur_set_offline,
76 .freeze = ur_pm_suspend,
119 static void urdev_free(
struct urdev *urd)
121 TRACE(
"urdev_free: %p\n", urd);
127 static void urdev_get(
struct urdev *urd)
151 sprintf(bus_id,
"0.0.%04x", devno);
155 urd = urdev_get_from_cdev(cdev);
160 static void urdev_put(
struct urdev *urd)
175 static int ur_pm_suspend(
struct ccw_device *cdev)
179 TRACE(
"ur_pm_suspend: cdev=%p\n", cdev);
181 pr_err(
"Unit record device %s is busy, %s refusing to "
182 "suspend.\n", dev_name(&cdev->
dev), ur_banner);
211 static void free_chan_prog(
struct ccw1 *
cpa)
230 static struct ccw1 *alloc_chan_prog(
const char __user *ubuf,
int rec_count,
237 TRACE(
"alloc_chan_prog(%p, %i, %i)\n", ubuf, rec_count, reclen);
244 cpa = kzalloc((rec_count + 1) *
sizeof(
struct ccw1),
249 for (i = 0; i < rec_count; i++) {
270 static int do_ur_io(
struct urdev *urd,
struct ccw1 *cpa)
276 TRACE(
"do_ur_io: cpa=%p\n", cpa);
288 TRACE(
"do_ur_io: ccw_device_start returned %d\n", rc);
293 TRACE(
"do_ur_io: I/O complete\n");
309 TRACE(
"ur_int_handler: intparm=0x%lx cstat=%02x dstat=%02x res=%u\n",
314 TRACE(
"ur_int_handler: unsolicited interrupt\n");
339 urd = urdev_get_from_cdev(
to_ccwdev(dev));
349 static int ur_create_attributes(
struct device *dev)
354 static void ur_remove_attributes(
struct device *dev)
366 static int get_urd_class(
struct urdev *urd)
368 static struct diag210 ur_diag210;
371 ur_diag210.vrdcdvno = urd->
dev_id.devno;
372 ur_diag210.vrdclen =
sizeof(
struct diag210);
379 return ur_diag210.vrdcvcla;
390 static struct urfile *urfile_alloc(
struct urdev *urd)
399 TRACE(
"urfile_alloc: urd=%p urf=%p rl=%zu\n", urd, urf,
405 static void urfile_free(
struct urfile *urf)
407 TRACE(
"urfile_free: urf=%p urd=%p\n", urf, urf->
urd);
415 size_t count,
size_t reclen, loff_t *ppos)
420 cpa = alloc_chan_prog(udata, count / reclen, reclen);
424 rc = do_ur_io(urd, cpa);
441 size_t count, loff_t *ppos)
445 TRACE(
"ur_write: count=%zu\n", count);
466 static int diag_position_to_record(
int devno,
int record)
470 cc =
diag14(record, devno, 0x28);
491 static int diag_read_file(
int devno,
char *buf)
495 cc =
diag14((
unsigned long) buf, devno, 0x00);
508 static ssize_t diag14_read(
struct file *file,
char __user *ubuf,
size_t count,
520 rc = diag_position_to_record(urd->
dev_id.devno, *offs /
PAGE_SIZE + 1);
534 rc = diag_read_file(urd->
dev_id.devno, buf);
540 if (reclen && (copied == 0) && (*offs < PAGE_SIZE))
542 len =
min(count - copied, PAGE_SIZE - res);
549 }
while (copied != count);
558 static ssize_t ur_read(
struct file *file,
char __user *ubuf,
size_t count,
564 TRACE(
"ur_read: count=%zu ppos=%li\n", count, (
unsigned long) *offs);
573 rc = diag14_read(file, ubuf, count, offs);
588 cc =
diag14((
unsigned long) buf, spid, 0xfff);
597 static int verify_uri_device(
struct urdev *urd)
608 rc = diag_read_next_file_info(fcb, 0);
624 rc = diag_read_file(urd->
dev_id.devno, buf);
625 if ((rc != 0) && (rc != -
ENODATA))
629 rc = diag_read_next_file_info(fcb, 0);
645 static int verify_device(
struct urdev *urd)
647 switch (urd->
class) {
651 return verify_uri_device(urd);
657 static int get_uri_file_reclen(
struct urdev *urd)
665 rc = diag_read_next_file_info(fcb, 0);
678 static int get_file_reclen(
struct urdev *urd)
680 switch (urd->
class) {
684 return get_uri_file_reclen(urd);
690 static int ur_open(
struct inode *
inode,
struct file *file)
695 unsigned short accmode;
706 devno =
MINOR(file->f_dentry->d_inode->i_rdev);
708 urd = urdev_get_from_devno(devno);
734 TRACE(
"ur_open: unsupported dev class (%d)\n", urd->
class);
739 rc = verify_device(urd);
743 urf = urfile_alloc(urd);
750 rc = get_file_reclen(urd);
752 goto fail_urfile_free;
769 static int ur_release(
struct inode *inode,
struct file *file)
773 TRACE(
"ur_release\n");
774 spin_lock(&urf->
urd->open_lock);
775 urf->
urd->open_flag--;
776 spin_unlock(&urf->
urd->open_lock);
783 static loff_t ur_llseek(
struct file *file, loff_t
offset,
int whence)
789 if (offset % PAGE_SIZE)
801 file->
f_pos = newpos;
808 .release = ur_release,
833 TRACE(
"ur_probe: cdev=%p\n", cdev);
836 urd = urdev_alloc(cdev);
842 rc = ur_create_attributes(&cdev->
dev);
847 cdev->
handler = ur_int_handler;
850 urd->
class = get_urd_class(urd);
851 if (urd->
class < 0) {
853 goto fail_remove_attr;
857 goto fail_remove_attr;
867 ur_remove_attributes(&cdev->
dev);
875 static int ur_set_online(
struct ccw_device *cdev)
881 TRACE(
"ur_set_online: cdev=%p\n", cdev);
884 urd = urdev_get_from_cdev(cdev);
897 minor = urd->
dev_id.devno;
898 major =
MAJOR(ur_first_dev_maj_min);
915 sprintf(node_id,
"vmrdr-%s", dev_name(&cdev->
dev));
917 sprintf(node_id,
"vmpun-%s", dev_name(&cdev->
dev));
919 sprintf(node_id,
"vmprt-%s", dev_name(&cdev->
dev));
926 NULL,
"%s", node_id);
927 if (IS_ERR(urd->
device)) {
928 rc = PTR_ERR(urd->
device);
929 TRACE(
"ur_set_online: device_create rc=%d\n", rc);
951 TRACE(
"ur_set_offline: cdev=%p\n", cdev);
952 urd = urdev_get_from_cdev(cdev);
963 TRACE(
"ur_set_offline: BUSY\n");
977 static int ur_set_offline(
struct ccw_device *cdev)
982 rc = ur_set_offline_force(cdev, 0);
987 static void ur_remove(
struct ccw_device *cdev)
991 TRACE(
"ur_remove\n");
996 ur_set_offline_force(cdev, 1);
997 ur_remove_attributes(&cdev->
dev);
1010 static int __init ur_init(
void)
1016 pr_err(
"The %s cannot be loaded without z/VM\n",
1031 if (IS_ERR(vmur_class)) {
1032 rc = PTR_ERR(vmur_class);
1038 goto fail_class_destroy;
1042 pr_err(
"Kernel function alloc_chrdev_region failed with "
1043 "error code %d\n", rc);
1044 goto fail_unregister_driver;
1048 pr_info(
"%s loaded.\n", ur_banner);
1051 fail_unregister_driver:
1060 static void __exit ur_exit(
void)
1066 pr_info(
"%s unloaded.\n", ur_banner);