Lines Matching defs:urd

90  * Each ur device (urd) contains a reference to its corresponding ccw device
91 * (cdev) using the urd->cdev pointer. Each ccw device has a reference to the
94 * urd references:
95 * - ur_probe gets a urd reference, ur_remove drops the reference
97 * - ur_open gets a urd reference, ur_release drops the reference
98 * (urf->urd)
101 * - urdev_alloc get a cdev reference (urd->cdev)
102 * - urdev_free drops the cdev reference (urd->cdev)
108 struct urdev *urd;
110 urd = kzalloc(sizeof(struct urdev), GFP_KERNEL);
111 if (!urd)
113 urd->reclen = cdev->id.driver_info;
114 ccw_device_get_id(cdev, &urd->dev_id);
115 mutex_init(&urd->io_mutex);
116 init_waitqueue_head(&urd->wait);
117 INIT_WORK(&urd->uevent_work, ur_uevent);
118 spin_lock_init(&urd->open_lock);
119 refcount_set(&urd->ref_count, 1);
120 urd->cdev = cdev;
122 return urd;
125 static void urdev_free(struct urdev *urd)
127 TRACE("urdev_free: %p\n", urd);
128 if (urd->cdev)
129 put_device(&urd->cdev->dev);
130 kfree(urd);
133 static void urdev_get(struct urdev *urd)
135 refcount_inc(&urd->ref_count);
140 struct urdev *urd;
144 urd = dev_get_drvdata(&cdev->dev);
145 if (urd)
146 urdev_get(urd);
148 return urd;
155 struct urdev *urd;
161 urd = urdev_get_from_cdev(cdev);
163 return urd;
166 static void urdev_put(struct urdev *urd)
168 if (refcount_dec_and_test(&urd->ref_count))
169 urdev_free(urd);
183 * on a completion event it publishes at urd->io_done. The function
254 static int do_ur_io(struct urdev *urd, struct ccw1 *cpa)
257 struct ccw_device *cdev = urd->cdev;
262 rc = mutex_lock_interruptible(&urd->io_mutex);
266 urd->io_done = &event;
281 mutex_unlock(&urd->io_mutex);
287 struct urdev *urd = container_of(ws, struct urdev, uevent_work);
293 kobject_uevent_env(&urd->cdev->dev.kobj, KOBJ_CHANGE, envp);
294 urdev_put(urd);
303 struct urdev *urd;
310 urd = dev_get_drvdata(&cdev->dev);
319 urdev_get(urd);
320 schedule_work(&urd->uevent_work);
327 urd->io_request_rc = PTR_ERR(irb);
329 urd->io_request_rc = 0;
331 urd->io_request_rc = -EIO;
333 complete(urd->io_done);
342 struct urdev *urd;
345 urd = urdev_get_from_cdev(to_ccwdev(dev));
346 if (!urd)
348 rc = sprintf(buf, "%zu\n", urd->reclen);
349 urdev_put(urd);
372 static int get_urd_class(struct urdev *urd)
377 ur_diag210.vrdcdvno = urd->dev_id.devno;
396 static struct urfile *urfile_alloc(struct urdev *urd)
403 urf->urd = urd;
405 TRACE("urfile_alloc: urd=%p urf=%p rl=%zu\n", urd, urf,
413 TRACE("urfile_free: urf=%p urd=%p\n", urf, urf->urd);
420 static ssize_t do_write(struct urdev *urd, const char __user *udata,
430 rc = do_ur_io(urd, cpa);
434 if (urd->io_request_rc) {
435 rc = urd->io_request_rc;
462 return do_write(urf->urd, udata, count, urf->dev_reclen, ppos);
521 struct urdev *urd;
523 urd = ((struct urfile *) file->private_data)->urd;
526 rc = diag_position_to_record(urd->dev_id.devno, *offs / PAGE_SIZE + 1);
540 rc = diag_read_file(urd->dev_id.devno, buf);
567 struct urdev *urd;
575 urd = ((struct urfile *) file->private_data)->urd;
576 rc = mutex_lock_interruptible(&urd->io_mutex);
580 mutex_unlock(&urd->io_mutex);
603 static int verify_uri_device(struct urdev *urd)
630 rc = diag_read_file(urd->dev_id.devno, buf);
651 static int verify_device(struct urdev *urd)
653 switch (urd->class) {
657 return verify_uri_device(urd);
663 static int get_uri_file_reclen(struct urdev *urd)
684 static int get_file_reclen(struct urdev *urd)
686 switch (urd->class) {
690 return get_uri_file_reclen(urd);
699 struct urdev *urd;
714 urd = urdev_get_from_devno(devno);
715 if (!urd) {
720 spin_lock(&urd->open_lock);
721 while (urd->open_flag) {
722 spin_unlock(&urd->open_lock);
727 if (wait_event_interruptible(urd->wait, urd->open_flag == 0)) {
731 spin_lock(&urd->open_lock);
733 urd->open_flag++;
734 spin_unlock(&urd->open_lock);
738 if (((accmode == O_RDONLY) && (urd->class != DEV_CLASS_UR_I)) ||
739 ((accmode == O_WRONLY) && (urd->class != DEV_CLASS_UR_O))) {
740 TRACE("ur_open: unsupported dev class (%d)\n", urd->class);
745 rc = verify_device(urd);
749 urf = urfile_alloc(urd);
755 urf->dev_reclen = urd->reclen;
756 rc = get_file_reclen(urd);
766 spin_lock(&urd->open_lock);
767 urd->open_flag--;
768 spin_unlock(&urd->open_lock);
770 urdev_put(urd);
780 spin_lock(&urf->urd->open_lock);
781 urf->urd->open_flag--;
782 spin_unlock(&urf->urd->open_lock);
783 wake_up_interruptible(&urf->urd->wait);
784 urdev_put(urf->urd);
818 * urd->char_device is used as indication that the online function has
823 struct urdev *urd;
829 urd = urdev_alloc(cdev);
830 if (!urd) {
842 urd->class = get_urd_class(urd);
843 if (urd->class < 0) {
844 rc = urd->class;
847 if ((urd->class != DEV_CLASS_UR_I) && (urd->class != DEV_CLASS_UR_O)) {
852 dev_set_drvdata(&cdev->dev, urd);
862 urdev_put(urd);
870 struct urdev *urd;
877 urd = urdev_get_from_cdev(cdev);
878 if (!urd) {
879 /* ur_remove already deleted our urd */
884 if (urd->char_device) {
890 minor = urd->dev_id.devno;
893 urd->char_device = cdev_alloc();
894 if (!urd->char_device) {
899 urd->char_device->ops = &ur_fops;
900 urd->char_device->owner = ur_fops.owner;
902 rc = cdev_add(urd->char_device, MKDEV(major, minor), 1);
905 if (urd->cdev->id.cu_type == READER_PUNCH_DEVTYPE) {
906 if (urd->class == DEV_CLASS_UR_I)
908 if (urd->class == DEV_CLASS_UR_O)
910 } else if (urd->cdev->id.cu_type == PRINTER_DEVTYPE) {
917 urd->device = device_create(&vmur_class, &cdev->dev,
918 urd->char_device->dev, NULL, "%s", node_id);
919 if (IS_ERR(urd->device)) {
920 rc = PTR_ERR(urd->device);
924 urdev_put(urd);
929 cdev_del(urd->char_device);
930 urd->char_device = NULL;
932 urdev_put(urd);
940 struct urdev *urd;
944 urd = urdev_get_from_cdev(cdev);
945 if (!urd)
946 /* ur_remove already deleted our urd */
948 if (!urd->char_device) {
953 if (!force && (refcount_read(&urd->ref_count) > 2)) {
954 /* There is still a user of urd (e.g. ur_open) */
959 if (cancel_work_sync(&urd->uevent_work)) {
961 urdev_put(urd);
963 device_destroy(&vmur_class, urd->char_device->dev);
964 cdev_del(urd->char_device);
965 urd->char_device = NULL;
969 urdev_put(urd);