Lines Matching full:device

3  *    basic function of the tape device driver
94 tape_medium_state_show(struct device *dev, struct device_attribute *attr, char *buf) in tape_medium_state_show()
106 tape_first_minor_show(struct device *dev, struct device_attribute *attr, char *buf) in tape_first_minor_show()
118 tape_state_show(struct device *dev, struct device_attribute *attr, char *buf) in tape_state_show()
131 tape_operation_show(struct device *dev, struct device_attribute *attr, char *buf) in tape_operation_show()
158 tape_blocksize_show(struct device *dev, struct device_attribute *attr, char *buf) in tape_blocksize_show()
187 tape_state_set(struct tape_device *device, enum tape_state newstate) in tape_state_set() argument
191 if (device->tape_state == TS_NOT_OPER) { in tape_state_set()
195 DBF_EVENT(4, "ts. dev: %x\n", device->first_minor); in tape_state_set()
197 if (device->tape_state < TS_SIZE && device->tape_state >=0 ) in tape_state_set()
198 str = tape_state_verbose[device->tape_state]; in tape_state_set()
208 device->tape_state = newstate; in tape_state_set()
209 wake_up(&device->state_change_wq); in tape_state_set()
213 struct tape_device *device; member
225 struct tape_device *device = p->device; in tape_med_state_work_handler() local
231 "unloaded\n", dev_name(&device->cdev->dev)); in tape_med_state_work_handler()
233 kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp); in tape_med_state_work_handler()
237 dev_name(&device->cdev->dev)); in tape_med_state_work_handler()
239 kobject_uevent_env(&device->cdev->dev.kobj, KOBJ_CHANGE, envp); in tape_med_state_work_handler()
244 tape_put_device(device); in tape_med_state_work_handler()
249 tape_med_state_work(struct tape_device *device, enum tape_medium_state state) in tape_med_state_work() argument
256 p->device = tape_get_device(device); in tape_med_state_work()
263 tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate) in tape_med_state_set() argument
267 oldstate = device->medium_state; in tape_med_state_set()
270 device->medium_state = newstate; in tape_med_state_set()
273 device->tape_generic_status |= GMT_DR_OPEN(~0); in tape_med_state_set()
275 tape_med_state_work(device, MS_UNLOADED); in tape_med_state_set()
278 device->tape_generic_status &= ~GMT_DR_OPEN(~0); in tape_med_state_set()
280 tape_med_state_work(device, MS_LOADED); in tape_med_state_set()
285 wake_up(&device->state_change_wq); in tape_med_state_set()
289 * Stop running ccw. Has to be called with the device lock held.
292 __tape_cancel_io(struct tape_device *device, struct tape_request *request) in __tape_cancel_io() argument
303 rc = ccw_device_clear(device->cdev, (long) request); in __tape_cancel_io()
311 schedule_delayed_work(&device->tape_dnr, 0); in __tape_cancel_io()
314 DBF_EXCEPTION(2, "device gone, retry\n"); in __tape_cancel_io()
328 * Add device into the sorted list, giving it the first
332 tape_assign_minor(struct tape_device *device) in tape_assign_minor() argument
348 device->first_minor = minor; in tape_assign_minor()
349 list_add_tail(&device->node, &tmp->node); in tape_assign_minor()
354 /* remove device from the list */
356 tape_remove_minor(struct tape_device *device) in tape_remove_minor() argument
359 list_del_init(&device->node); in tape_remove_minor()
360 device->first_minor = -1; in tape_remove_minor()
365 * Set a device online.
367 * This function is called by the common I/O layer to move a device from the
369 * If we return an error (RC < 0) the device remains in the offline state. This
370 * can happen if the device is assigned somewhere else, for example.
373 tape_generic_online(struct tape_device *device, in tape_generic_online() argument
378 DBF_LH(6, "tape_enable_device(%p, %p)\n", device, discipline); in tape_generic_online()
380 if (device->tape_state != TS_INIT) { in tape_generic_online()
381 DBF_LH(3, "Tapestate not INIT (%d)\n", device->tape_state); in tape_generic_online()
385 init_timer(&device->lb_timeout); in tape_generic_online()
386 device->lb_timeout.function = tape_long_busy_timeout; in tape_generic_online()
388 /* Let the discipline have a go at the device. */ in tape_generic_online()
389 device->discipline = discipline; in tape_generic_online()
394 rc = discipline->setup_device(device); in tape_generic_online()
397 rc = tape_assign_minor(device); in tape_generic_online()
401 rc = tapechar_setup_device(device); in tape_generic_online()
404 rc = tapeblock_setup_device(device); in tape_generic_online()
408 tape_state_set(device, TS_UNUSED); in tape_generic_online()
410 DBF_LH(3, "(%08x): Drive set online\n", device->cdev_id); in tape_generic_online()
415 tapechar_cleanup_device(device); in tape_generic_online()
417 tape_remove_minor(device); in tape_generic_online()
419 device->discipline->cleanup_device(device); in tape_generic_online()
420 device->discipline = NULL; in tape_generic_online()
427 tape_cleanup_device(struct tape_device *device) in tape_cleanup_device() argument
429 tapeblock_cleanup_device(device); in tape_cleanup_device()
430 tapechar_cleanup_device(device); in tape_cleanup_device()
431 device->discipline->cleanup_device(device); in tape_cleanup_device()
432 module_put(device->discipline->owner); in tape_cleanup_device()
433 tape_remove_minor(device); in tape_cleanup_device()
434 tape_med_state_set(device, MS_UNKNOWN); in tape_cleanup_device()
438 * Suspend device.
441 * request. We refuse to suspend if the device is loaded or in use for the
445 * during DETACH processing (unless the tape device was attached with the
447 * resume the original state of the tape device, since we would need to
452 struct tape_device *device; in tape_generic_pm_suspend() local
454 device = dev_get_drvdata(&cdev->dev); in tape_generic_pm_suspend()
455 if (!device) { in tape_generic_pm_suspend()
460 device->cdev_id, device); in tape_generic_pm_suspend()
462 if (device->medium_state != MS_UNLOADED) { in tape_generic_pm_suspend()
463 pr_err("A cartridge is loaded in tape device %s, " in tape_generic_pm_suspend()
468 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_pm_suspend()
469 switch (device->tape_state) { in tape_generic_pm_suspend()
473 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_pm_suspend()
476 pr_err("Tape device %s is busy, refusing to " in tape_generic_pm_suspend()
478 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_pm_suspend()
482 DBF_LH(3, "(%08x): Drive suspended.\n", device->cdev_id); in tape_generic_pm_suspend()
487 * Set device offline.
496 struct tape_device *device; in tape_generic_offline() local
498 device = dev_get_drvdata(&cdev->dev); in tape_generic_offline()
499 if (!device) { in tape_generic_offline()
504 device->cdev_id, device); in tape_generic_offline()
506 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_offline()
507 switch (device->tape_state) { in tape_generic_offline()
510 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_offline()
513 tape_state_set(device, TS_INIT); in tape_generic_offline()
514 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_offline()
515 tape_cleanup_device(device); in tape_generic_offline()
520 device->cdev_id); in tape_generic_offline()
521 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_offline()
525 DBF_LH(3, "(%08x): Drive set offline.\n", device->cdev_id); in tape_generic_offline()
530 * Allocate memory for a new device structure.
535 struct tape_device *device; in tape_alloc_device() local
537 device = kzalloc(sizeof(struct tape_device), GFP_KERNEL); in tape_alloc_device()
538 if (device == NULL) { in tape_alloc_device()
542 device->modeset_byte = kmalloc(1, GFP_KERNEL | GFP_DMA); in tape_alloc_device()
543 if (device->modeset_byte == NULL) { in tape_alloc_device()
545 kfree(device); in tape_alloc_device()
548 mutex_init(&device->mutex); in tape_alloc_device()
549 INIT_LIST_HEAD(&device->req_queue); in tape_alloc_device()
550 INIT_LIST_HEAD(&device->node); in tape_alloc_device()
551 init_waitqueue_head(&device->state_change_wq); in tape_alloc_device()
552 init_waitqueue_head(&device->wait_queue); in tape_alloc_device()
553 device->tape_state = TS_INIT; in tape_alloc_device()
554 device->medium_state = MS_UNKNOWN; in tape_alloc_device()
555 *device->modeset_byte = 0; in tape_alloc_device()
556 device->first_minor = -1; in tape_alloc_device()
557 atomic_set(&device->ref_count, 1); in tape_alloc_device()
558 INIT_DELAYED_WORK(&device->tape_dnr, tape_delayed_next_request); in tape_alloc_device()
560 return device; in tape_alloc_device()
564 * Get a reference to an existing device structure. This will automatically
568 tape_get_device(struct tape_device *device) in tape_get_device() argument
572 count = atomic_inc_return(&device->ref_count); in tape_get_device()
573 DBF_EVENT(4, "tape_get_device(%p) = %i\n", device, count); in tape_get_device()
574 return device; in tape_get_device()
579 * reference counter reaches zero free the device structure.
584 tape_put_device(struct tape_device *device) in tape_put_device() argument
588 count = atomic_dec_return(&device->ref_count); in tape_put_device()
589 DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, count); in tape_put_device()
592 kfree(device->modeset_byte); in tape_put_device()
593 kfree(device); in tape_put_device()
598 * Find tape device by a device index.
603 struct tape_device *device, *tmp; in tape_find_device() local
605 device = ERR_PTR(-ENODEV); in tape_find_device()
609 device = tape_get_device(tmp); in tape_find_device()
614 return device; in tape_find_device()
623 struct tape_device *device; in tape_generic_probe() local
627 device = tape_alloc_device(); in tape_generic_probe()
628 if (IS_ERR(device)) in tape_generic_probe()
634 tape_put_device(device); in tape_generic_probe()
637 dev_set_drvdata(&cdev->dev, device); in tape_generic_probe()
639 device->cdev = cdev; in tape_generic_probe()
641 device->cdev_id = devid_to_int(&dev_id); in tape_generic_probe()
646 __tape_discard_requests(struct tape_device *device) in __tape_discard_requests() argument
651 list_for_each_safe(l, n, &device->req_queue) { in __tape_discard_requests()
658 request->device = NULL; in __tape_discard_requests()
659 tape_put_device(device); in __tape_discard_requests()
669 * This function is called whenever the common I/O layer detects the device
675 struct tape_device * device; in tape_generic_remove() local
677 device = dev_get_drvdata(&cdev->dev); in tape_generic_remove()
678 if (!device) { in tape_generic_remove()
681 DBF_LH(3, "(%08x): tape_generic_remove(%p)\n", device->cdev_id, cdev); in tape_generic_remove()
683 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_remove()
684 switch (device->tape_state) { in tape_generic_remove()
686 tape_state_set(device, TS_NOT_OPER); in tape_generic_remove()
691 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_remove()
695 * Need only to release the device. in tape_generic_remove()
697 tape_state_set(device, TS_NOT_OPER); in tape_generic_remove()
698 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_remove()
699 tape_cleanup_device(device); in tape_generic_remove()
708 device->cdev_id); in tape_generic_remove()
710 "use\n", dev_name(&device->cdev->dev)); in tape_generic_remove()
711 tape_state_set(device, TS_NOT_OPER); in tape_generic_remove()
712 __tape_discard_requests(device); in tape_generic_remove()
713 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_generic_remove()
714 tape_cleanup_device(device); in tape_generic_remove()
717 device = dev_get_drvdata(&cdev->dev); in tape_generic_remove()
718 if (device) { in tape_generic_remove()
721 tape_put_device(device); in tape_generic_remove()
776 if (request->device) in tape_free_request()
777 tape_put_device(request->device); in tape_free_request()
784 __tape_start_io(struct tape_device *device, struct tape_request *request) in __tape_start_io() argument
790 device->discipline->check_locate(device, request); in __tape_start_io()
793 device->cdev, in __tape_start_io()
804 schedule_delayed_work(&device->tape_dnr, 0); in __tape_start_io()
814 __tape_start_next_request(struct tape_device *device) in __tape_start_next_request() argument
820 DBF_LH(6, "__tape_start_next_request(%p)\n", device); in __tape_start_next_request()
825 list_for_each_safe(l, n, &device->req_queue) { in __tape_start_next_request()
849 rc = __tape_cancel_io(device, request); in __tape_start_next_request()
851 rc = __tape_start_io(device, request); in __tape_start_next_request()
872 struct tape_device *device = in tape_delayed_next_request() local
875 DBF_LH(6, "tape_delayed_next_request(%p)\n", device); in tape_delayed_next_request()
876 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_delayed_next_request()
877 __tape_start_next_request(device); in tape_delayed_next_request()
878 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_delayed_next_request()
884 struct tape_device *device; in tape_long_busy_timeout() local
886 device = (struct tape_device *) data; in tape_long_busy_timeout()
887 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_long_busy_timeout()
888 request = list_entry(device->req_queue.next, struct tape_request, list); in tape_long_busy_timeout()
890 DBF_LH(6, "%08x: Long busy timeout.\n", device->cdev_id); in tape_long_busy_timeout()
891 __tape_start_next_request(device); in tape_long_busy_timeout()
892 device->lb_timeout.data = 0UL; in tape_long_busy_timeout()
893 tape_put_device(device); in tape_long_busy_timeout()
894 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_long_busy_timeout()
899 struct tape_device * device, in __tape_end_request() argument
903 DBF_LH(6, "__tape_end_request(%p, %p, %i)\n", device, request, rc); in __tape_end_request()
917 if (!list_empty(&device->req_queue)) in __tape_end_request()
918 __tape_start_next_request(device); in __tape_end_request()
925 tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request, in tape_dump_sense_dbf() argument
937 DBF_EVENT(3, "DEVICE: %08x OP\t: %s\n", device->cdev_id, op); in tape_dump_sense_dbf()
948 * the device lock held.
951 __tape_start_request(struct tape_device *device, struct tape_request *request) in __tape_start_request() argument
961 if (device->tape_state == TS_INIT) in __tape_start_request()
963 if (device->tape_state == TS_UNUSED) in __tape_start_request()
966 if (device->tape_state == TS_BLKUSE) in __tape_start_request()
968 if (device->tape_state != TS_IN_USE) in __tape_start_request()
972 /* Increase use count of device for the added request. */ in __tape_start_request()
973 request->device = tape_get_device(device); in __tape_start_request()
975 if (list_empty(&device->req_queue)) { in __tape_start_request()
977 rc = __tape_start_io(device, request); in __tape_start_request()
982 list_add(&request->list, &device->req_queue); in __tape_start_request()
986 list_add_tail(&request->list, &device->req_queue); in __tape_start_request()
996 tape_do_io_async(struct tape_device *device, struct tape_request *request) in tape_do_io_async() argument
1000 DBF_LH(6, "tape_do_io_async(%p, %p)\n", device, request); in tape_do_io_async()
1002 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_async()
1004 rc = __tape_start_request(device, request); in tape_do_io_async()
1005 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_async()
1022 tape_do_io(struct tape_device *device, struct tape_request *request) in tape_do_io() argument
1026 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io()
1029 request->callback_data = &device->wait_queue; in tape_do_io()
1031 rc = __tape_start_request(device, request); in tape_do_io()
1032 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io()
1036 wait_event(device->wait_queue, (request->callback == NULL)); in tape_do_io()
1054 tape_do_io_interruptible(struct tape_device *device, in tape_do_io_interruptible() argument
1059 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_interruptible()
1062 request->callback_data = &device->wait_queue; in tape_do_io_interruptible()
1063 rc = __tape_start_request(device, request); in tape_do_io_interruptible()
1064 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_interruptible()
1068 rc = wait_event_interruptible(device->wait_queue, in tape_do_io_interruptible()
1075 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_interruptible()
1076 rc = __tape_cancel_io(device, request); in tape_do_io_interruptible()
1077 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_do_io_interruptible()
1082 device->wait_queue, in tape_do_io_interruptible()
1087 DBF_EVENT(3, "IO stopped on %08x\n", device->cdev_id); in tape_do_io_interruptible()
1097 tape_cancel_io(struct tape_device *device, struct tape_request *request) in tape_cancel_io() argument
1101 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_cancel_io()
1102 rc = __tape_cancel_io(device, request); in tape_cancel_io()
1103 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_cancel_io()
1113 struct tape_device *device; in __tape_do_irq() local
1117 device = dev_get_drvdata(&cdev->dev); in __tape_do_irq()
1118 if (device == NULL) { in __tape_do_irq()
1123 DBF_LH(6, "__tape_do_irq(device=%p, request=%p)\n", device, request); in __tape_do_irq()
1131 device->cdev_id); in __tape_do_irq()
1133 __tape_end_request(device, request, -EIO); in __tape_do_irq()
1137 device->cdev_id, PTR_ERR(irb)); in __tape_do_irq()
1153 device->cdev_id, irb->scsw.cmd.cc, irb->scsw.cmd.fctl); in __tape_do_irq()
1155 schedule_delayed_work(&device->tape_dnr, HZ); in __tape_do_irq()
1163 !list_empty(&device->req_queue)) { in __tape_do_irq()
1166 req = list_entry(device->req_queue.next, in __tape_do_irq()
1169 DBF_EVENT(3, "(%08x): del timer\n", device->cdev_id); in __tape_do_irq()
1170 if (del_timer(&device->lb_timeout)) { in __tape_do_irq()
1171 device->lb_timeout.data = 0UL; in __tape_do_irq()
1172 tape_put_device(device); in __tape_do_irq()
1173 __tape_start_next_request(device); in __tape_do_irq()
1181 device->tape_generic_status |= GMT_ONLINE(~0); in __tape_do_irq()
1183 device->tape_generic_status &= ~GMT_ONLINE(~0); in __tape_do_irq()
1187 * and device end is unusual. Log the sense data. in __tape_do_irq()
1190 tape_dump_sense_dbf(device, request, irb); in __tape_do_irq()
1192 /* Upon normal completion the device _is_ online */ in __tape_do_irq()
1193 device->tape_generic_status |= GMT_ONLINE(~0); in __tape_do_irq()
1195 if (device->tape_state == TS_NOT_OPER) { in __tape_do_irq()
1196 DBF_EVENT(6, "tape:device is not operational\n"); in __tape_do_irq()
1205 __tape_end_request(device, request, -EIO); in __tape_do_irq()
1209 rc = device->discipline->irq(device, request, irb); in __tape_do_irq()
1219 /* Upon normal completion the device _is_ online */ in __tape_do_irq()
1220 device->tape_generic_status |= GMT_ONLINE(~0); in __tape_do_irq()
1221 __tape_end_request(device, request, rc); in __tape_do_irq()
1226 device->lb_timeout.data = in __tape_do_irq()
1227 (unsigned long) tape_get_device(device); in __tape_do_irq()
1228 device->lb_timeout.expires = jiffies + in __tape_do_irq()
1230 DBF_EVENT(3, "(%08x): add timer\n", device->cdev_id); in __tape_do_irq()
1231 add_timer(&device->lb_timeout); in __tape_do_irq()
1235 rc = __tape_start_io(device, request); in __tape_do_irq()
1237 __tape_end_request(device, request, rc); in __tape_do_irq()
1240 rc = __tape_cancel_io(device, request); in __tape_do_irq()
1242 __tape_end_request(device, request, rc); in __tape_do_irq()
1247 __tape_end_request(device, request, -EIO); in __tape_do_irq()
1249 __tape_end_request(device, request, rc); in __tape_do_irq()
1256 * Tape device open function used by tape_char & tape_block frontends.
1259 tape_open(struct tape_device *device) in tape_open() argument
1263 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_open()
1264 if (device->tape_state == TS_NOT_OPER) { in tape_open()
1267 } else if (device->tape_state == TS_IN_USE) { in tape_open()
1270 } else if (device->tape_state == TS_BLKUSE) { in tape_open()
1273 } else if (device->discipline != NULL && in tape_open()
1274 !try_module_get(device->discipline->owner)) { in tape_open()
1278 tape_state_set(device, TS_IN_USE); in tape_open()
1281 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_open()
1286 * Tape device release function used by tape_char & tape_block frontends.
1289 tape_release(struct tape_device *device) in tape_release() argument
1291 spin_lock_irq(get_ccwdev_lock(device->cdev)); in tape_release()
1292 if (device->tape_state == TS_IN_USE) in tape_release()
1293 tape_state_set(device, TS_UNUSED); in tape_release()
1294 module_put(device->discipline->owner); in tape_release()
1295 spin_unlock_irq(get_ccwdev_lock(device->cdev)); in tape_release()
1303 tape_mtop(struct tape_device *device, int mt_op, int mt_count) in tape_mtop() argument
1314 fn = device->discipline->mtop_array[mt_op]; in tape_mtop()
1323 if ((rc = fn(device, 500)) != 0) in tape_mtop()
1326 rc = fn(device, mt_count); in tape_mtop()
1328 rc = fn(device, mt_count); in tape_mtop()
1368 MODULE_DESCRIPTION("Linux on zSeries channel attached tape device driver");