Lines Matching refs:urd
106 struct urdev *urd; in urdev_alloc() local
108 urd = kzalloc(sizeof(struct urdev), GFP_KERNEL); in urdev_alloc()
109 if (!urd) in urdev_alloc()
111 urd->reclen = cdev->id.driver_info; in urdev_alloc()
112 ccw_device_get_id(cdev, &urd->dev_id); in urdev_alloc()
113 mutex_init(&urd->io_mutex); in urdev_alloc()
114 init_waitqueue_head(&urd->wait); in urdev_alloc()
115 INIT_WORK(&urd->uevent_work, ur_uevent); in urdev_alloc()
116 spin_lock_init(&urd->open_lock); in urdev_alloc()
117 refcount_set(&urd->ref_count, 1); in urdev_alloc()
118 urd->cdev = cdev; in urdev_alloc()
120 return urd; in urdev_alloc()
123 static void urdev_free(struct urdev *urd) in urdev_free() argument
125 TRACE("urdev_free: %p\n", urd); in urdev_free()
126 if (urd->cdev) in urdev_free()
127 put_device(&urd->cdev->dev); in urdev_free()
128 kfree(urd); in urdev_free()
131 static void urdev_get(struct urdev *urd) in urdev_get() argument
133 refcount_inc(&urd->ref_count); in urdev_get()
138 struct urdev *urd; in urdev_get_from_cdev() local
142 urd = dev_get_drvdata(&cdev->dev); in urdev_get_from_cdev()
143 if (urd) in urdev_get_from_cdev()
144 urdev_get(urd); in urdev_get_from_cdev()
146 return urd; in urdev_get_from_cdev()
153 struct urdev *urd; in urdev_get_from_devno() local
159 urd = urdev_get_from_cdev(cdev); in urdev_get_from_devno()
161 return urd; in urdev_get_from_devno()
164 static void urdev_put(struct urdev *urd) in urdev_put() argument
166 if (refcount_dec_and_test(&urd->ref_count)) in urdev_put()
167 urdev_free(urd); in urdev_put()
252 static int do_ur_io(struct urdev *urd, struct ccw1 *cpa) in do_ur_io() argument
255 struct ccw_device *cdev = urd->cdev; in do_ur_io()
260 rc = mutex_lock_interruptible(&urd->io_mutex); in do_ur_io()
264 urd->io_done = &event; in do_ur_io()
279 mutex_unlock(&urd->io_mutex); in do_ur_io()
285 struct urdev *urd = container_of(ws, struct urdev, uevent_work); in ur_uevent() local
291 kobject_uevent_env(&urd->cdev->dev.kobj, KOBJ_CHANGE, envp); in ur_uevent()
292 urdev_put(urd); in ur_uevent()
301 struct urdev *urd; in ur_int_handler() local
308 urd = dev_get_drvdata(&cdev->dev); in ur_int_handler()
317 urdev_get(urd); in ur_int_handler()
318 schedule_work(&urd->uevent_work); in ur_int_handler()
325 urd->io_request_rc = PTR_ERR(irb); in ur_int_handler()
327 urd->io_request_rc = 0; in ur_int_handler()
329 urd->io_request_rc = -EIO; in ur_int_handler()
331 complete(urd->io_done); in ur_int_handler()
340 struct urdev *urd; in ur_attr_reclen_show() local
343 urd = urdev_get_from_cdev(to_ccwdev(dev)); in ur_attr_reclen_show()
344 if (!urd) in ur_attr_reclen_show()
346 rc = sprintf(buf, "%zu\n", urd->reclen); in ur_attr_reclen_show()
347 urdev_put(urd); in ur_attr_reclen_show()
370 static int get_urd_class(struct urdev *urd) in get_urd_class() argument
375 ur_diag210.vrdcdvno = urd->dev_id.devno; in get_urd_class()
394 static struct urfile *urfile_alloc(struct urdev *urd) in urfile_alloc() argument
401 urf->urd = urd; in urfile_alloc()
403 TRACE("urfile_alloc: urd=%p urf=%p rl=%zu\n", urd, urf, in urfile_alloc()
411 TRACE("urfile_free: urf=%p urd=%p\n", urf, urf->urd); in urfile_free()
418 static ssize_t do_write(struct urdev *urd, const char __user *udata, in do_write() argument
428 rc = do_ur_io(urd, cpa); in do_write()
432 if (urd->io_request_rc) { in do_write()
433 rc = urd->io_request_rc; in do_write()
460 return do_write(urf->urd, udata, count, urf->dev_reclen, ppos); in ur_write()
519 struct urdev *urd; in diag14_read() local
521 urd = ((struct urfile *) file->private_data)->urd; in diag14_read()
524 rc = diag_position_to_record(urd->dev_id.devno, *offs / PAGE_SIZE + 1); in diag14_read()
538 rc = diag_read_file(urd->dev_id.devno, buf); in diag14_read()
565 struct urdev *urd; in ur_read() local
573 urd = ((struct urfile *) file->private_data)->urd; in ur_read()
574 rc = mutex_lock_interruptible(&urd->io_mutex); in ur_read()
578 mutex_unlock(&urd->io_mutex); in ur_read()
601 static int verify_uri_device(struct urdev *urd) in verify_uri_device() argument
628 rc = diag_read_file(urd->dev_id.devno, buf); in verify_uri_device()
649 static int verify_device(struct urdev *urd) in verify_device() argument
651 switch (urd->class) { in verify_device()
655 return verify_uri_device(urd); in verify_device()
661 static int get_uri_file_reclen(struct urdev *urd) in get_uri_file_reclen() argument
682 static int get_file_reclen(struct urdev *urd) in get_file_reclen() argument
684 switch (urd->class) { in get_file_reclen()
688 return get_uri_file_reclen(urd); in get_file_reclen()
697 struct urdev *urd; in ur_open() local
712 urd = urdev_get_from_devno(devno); in ur_open()
713 if (!urd) { in ur_open()
718 spin_lock(&urd->open_lock); in ur_open()
719 while (urd->open_flag) { in ur_open()
720 spin_unlock(&urd->open_lock); in ur_open()
725 if (wait_event_interruptible(urd->wait, urd->open_flag == 0)) { in ur_open()
729 spin_lock(&urd->open_lock); in ur_open()
731 urd->open_flag++; in ur_open()
732 spin_unlock(&urd->open_lock); in ur_open()
736 if (((accmode == O_RDONLY) && (urd->class != DEV_CLASS_UR_I)) || in ur_open()
737 ((accmode == O_WRONLY) && (urd->class != DEV_CLASS_UR_O))) { in ur_open()
738 TRACE("ur_open: unsupported dev class (%d)\n", urd->class); in ur_open()
743 rc = verify_device(urd); in ur_open()
747 urf = urfile_alloc(urd); in ur_open()
753 urf->dev_reclen = urd->reclen; in ur_open()
754 rc = get_file_reclen(urd); in ur_open()
764 spin_lock(&urd->open_lock); in ur_open()
765 urd->open_flag--; in ur_open()
766 spin_unlock(&urd->open_lock); in ur_open()
768 urdev_put(urd); in ur_open()
778 spin_lock(&urf->urd->open_lock); in ur_release()
779 urf->urd->open_flag--; in ur_release()
780 spin_unlock(&urf->urd->open_lock); in ur_release()
781 wake_up_interruptible(&urf->urd->wait); in ur_release()
782 urdev_put(urf->urd); in ur_release()
821 struct urdev *urd; in ur_probe() local
827 urd = urdev_alloc(cdev); in ur_probe()
828 if (!urd) { in ur_probe()
840 urd->class = get_urd_class(urd); in ur_probe()
841 if (urd->class < 0) { in ur_probe()
842 rc = urd->class; in ur_probe()
845 if ((urd->class != DEV_CLASS_UR_I) && (urd->class != DEV_CLASS_UR_O)) { in ur_probe()
850 dev_set_drvdata(&cdev->dev, urd); in ur_probe()
860 urdev_put(urd); in ur_probe()
868 struct urdev *urd; in ur_set_online() local
875 urd = urdev_get_from_cdev(cdev); in ur_set_online()
876 if (!urd) { in ur_set_online()
882 if (urd->char_device) { in ur_set_online()
888 minor = urd->dev_id.devno; in ur_set_online()
891 urd->char_device = cdev_alloc(); in ur_set_online()
892 if (!urd->char_device) { in ur_set_online()
897 urd->char_device->ops = &ur_fops; in ur_set_online()
898 urd->char_device->owner = ur_fops.owner; in ur_set_online()
900 rc = cdev_add(urd->char_device, MKDEV(major, minor), 1); in ur_set_online()
903 if (urd->cdev->id.cu_type == READER_PUNCH_DEVTYPE) { in ur_set_online()
904 if (urd->class == DEV_CLASS_UR_I) in ur_set_online()
906 if (urd->class == DEV_CLASS_UR_O) in ur_set_online()
908 } else if (urd->cdev->id.cu_type == PRINTER_DEVTYPE) { in ur_set_online()
915 urd->device = device_create(vmur_class, &cdev->dev, in ur_set_online()
916 urd->char_device->dev, NULL, "%s", node_id); in ur_set_online()
917 if (IS_ERR(urd->device)) { in ur_set_online()
918 rc = PTR_ERR(urd->device); in ur_set_online()
922 urdev_put(urd); in ur_set_online()
927 cdev_del(urd->char_device); in ur_set_online()
928 urd->char_device = NULL; in ur_set_online()
930 urdev_put(urd); in ur_set_online()
938 struct urdev *urd; in ur_set_offline_force() local
942 urd = urdev_get_from_cdev(cdev); in ur_set_offline_force()
943 if (!urd) in ur_set_offline_force()
946 if (!urd->char_device) { in ur_set_offline_force()
951 if (!force && (refcount_read(&urd->ref_count) > 2)) { in ur_set_offline_force()
957 if (cancel_work_sync(&urd->uevent_work)) { in ur_set_offline_force()
959 urdev_put(urd); in ur_set_offline_force()
961 device_destroy(vmur_class, urd->char_device->dev); in ur_set_offline_force()
962 cdev_del(urd->char_device); in ur_set_offline_force()
963 urd->char_device = NULL; in ur_set_offline_force()
967 urdev_put(urd); in ur_set_offline_force()