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