Lines Matching refs:urd

86  * Each ur device (urd) contains a reference to its corresponding ccw device
87 * (cdev) using the urd->cdev pointer. Each ccw device has a reference to the
90 * urd references:
91 * - ur_probe gets a urd reference, ur_remove drops the reference
93 * - ur_open gets a urd reference, ur_release drops the reference
94 * (urf->urd)
97 * - urdev_alloc get a cdev reference (urd->cdev)
98 * - urdev_free drops the cdev reference (urd->cdev)
104 struct urdev *urd;
106 urd = kzalloc(sizeof(struct urdev), GFP_KERNEL);
107 if (!urd)
109 urd->reclen = cdev->id.driver_info;
110 ccw_device_get_id(cdev, &urd->dev_id);
111 mutex_init(&urd->io_mutex);
112 init_waitqueue_head(&urd->wait);
113 spin_lock_init(&urd->open_lock);
114 refcount_set(&urd->ref_count, 1);
115 urd->cdev = cdev;
117 return urd;
120 static void urdev_free(struct urdev *urd)
122 TRACE("urdev_free: %p\n", urd);
123 if (urd->cdev)
124 put_device(&urd->cdev->dev);
125 kfree(urd);
128 static void urdev_get(struct urdev *urd)
130 refcount_inc(&urd->ref_count);
135 struct urdev *urd;
139 urd = dev_get_drvdata(&cdev->dev);
140 if (urd)
141 urdev_get(urd);
143 return urd;
150 struct urdev *urd;
156 urd = urdev_get_from_cdev(cdev);
158 return urd;
161 static void urdev_put(struct urdev *urd)
163 if (refcount_dec_and_test(&urd->ref_count))
164 urdev_free(urd);
178 struct urdev *urd = dev_get_drvdata(&cdev->dev);
181 if (urd->open_flag) {
200 * on a completion event it publishes at urd->io_done. The function
271 static int do_ur_io(struct urdev *urd, struct ccw1 *cpa)
274 struct ccw_device *cdev = urd->cdev;
279 rc = mutex_lock_interruptible(&urd->io_mutex);
283 urd->io_done = &event;
298 mutex_unlock(&urd->io_mutex);
308 struct urdev *urd;
319 urd = dev_get_drvdata(&cdev->dev);
320 BUG_ON(!urd);
323 urd->io_request_rc = PTR_ERR(irb);
325 urd->io_request_rc = 0;
327 urd->io_request_rc = -EIO;
329 complete(urd->io_done);
338 struct urdev *urd;
341 urd = urdev_get_from_cdev(to_ccwdev(dev));
342 if (!urd)
344 rc = sprintf(buf, "%zu\n", urd->reclen);
345 urdev_put(urd);
368 static int get_urd_class(struct urdev *urd)
373 ur_diag210.vrdcdvno = urd->dev_id.devno;
392 static struct urfile *urfile_alloc(struct urdev *urd)
399 urf->urd = urd;
401 TRACE("urfile_alloc: urd=%p urf=%p rl=%zu\n", urd, urf,
409 TRACE("urfile_free: urf=%p urd=%p\n", urf, urf->urd);
416 static ssize_t do_write(struct urdev *urd, const char __user *udata,
426 rc = do_ur_io(urd, cpa);
430 if (urd->io_request_rc) {
431 rc = urd->io_request_rc;
458 return do_write(urf->urd, udata, count, urf->dev_reclen, ppos);
517 struct urdev *urd;
519 urd = ((struct urfile *) file->private_data)->urd;
522 rc = diag_position_to_record(urd->dev_id.devno, *offs / PAGE_SIZE + 1);
536 rc = diag_read_file(urd->dev_id.devno, buf);
563 struct urdev *urd;
571 urd = ((struct urfile *) file->private_data)->urd;
572 rc = mutex_lock_interruptible(&urd->io_mutex);
576 mutex_unlock(&urd->io_mutex);
599 static int verify_uri_device(struct urdev *urd)
626 rc = diag_read_file(urd->dev_id.devno, buf);
647 static int verify_device(struct urdev *urd)
649 switch (urd->class) {
653 return verify_uri_device(urd);
659 static int get_uri_file_reclen(struct urdev *urd)
680 static int get_file_reclen(struct urdev *urd)
682 switch (urd->class) {
686 return get_uri_file_reclen(urd);
695 struct urdev *urd;
710 urd = urdev_get_from_devno(devno);
711 if (!urd) {
716 spin_lock(&urd->open_lock);
717 while (urd->open_flag) {
718 spin_unlock(&urd->open_lock);
723 if (wait_event_interruptible(urd->wait, urd->open_flag == 0)) {
727 spin_lock(&urd->open_lock);
729 urd->open_flag++;
730 spin_unlock(&urd->open_lock);
734 if (((accmode == O_RDONLY) && (urd->class != DEV_CLASS_UR_I)) ||
735 ((accmode == O_WRONLY) && (urd->class != DEV_CLASS_UR_O))) {
736 TRACE("ur_open: unsupported dev class (%d)\n", urd->class);
741 rc = verify_device(urd);
745 urf = urfile_alloc(urd);
751 urf->dev_reclen = urd->reclen;
752 rc = get_file_reclen(urd);
762 spin_lock(&urd->open_lock);
763 urd->open_flag--;
764 spin_unlock(&urd->open_lock);
766 urdev_put(urd);
776 spin_lock(&urf->urd->open_lock);
777 urf->urd->open_flag--;
778 spin_unlock(&urf->urd->open_lock);
779 wake_up_interruptible(&urf->urd->wait);
780 urdev_put(urf->urd);
814 * urd->char_device is used as indication that the online function has
819 struct urdev *urd;
825 urd = urdev_alloc(cdev);
826 if (!urd) {
839 urd->class = get_urd_class(urd);
840 if (urd->class < 0) {
841 rc = urd->class;
844 if ((urd->class != DEV_CLASS_UR_I) && (urd->class != DEV_CLASS_UR_O)) {
849 dev_set_drvdata(&cdev->dev, urd);
858 urdev_put(urd);
866 struct urdev *urd;
873 urd = urdev_get_from_cdev(cdev);
874 if (!urd) {
875 /* ur_remove already deleted our urd */
880 if (urd->char_device) {
886 minor = urd->dev_id.devno;
889 urd->char_device = cdev_alloc();
890 if (!urd->char_device) {
895 urd->char_device->ops = &ur_fops;
896 urd->char_device->owner = ur_fops.owner;
898 rc = cdev_add(urd->char_device, MKDEV(major, minor), 1);
901 if (urd->cdev->id.cu_type == READER_PUNCH_DEVTYPE) {
902 if (urd->class == DEV_CLASS_UR_I)
904 if (urd->class == DEV_CLASS_UR_O)
906 } else if (urd->cdev->id.cu_type == PRINTER_DEVTYPE) {
913 urd->device = device_create(vmur_class, &cdev->dev,
914 urd->char_device->dev, NULL, "%s", node_id);
915 if (IS_ERR(urd->device)) {
916 rc = PTR_ERR(urd->device);
920 urdev_put(urd);
925 cdev_del(urd->char_device);
926 urd->char_device = NULL;
928 urdev_put(urd);
936 struct urdev *urd;
940 urd = urdev_get_from_cdev(cdev);
941 if (!urd)
942 /* ur_remove already deleted our urd */
944 if (!urd->char_device) {
949 if (!force && (refcount_read(&urd->ref_count) > 2)) {
950 /* There is still a user of urd (e.g. ur_open) */
955 device_destroy(vmur_class, urd->char_device->dev);
956 cdev_del(urd->char_device);
957 urd->char_device = NULL;
961 urdev_put(urd);