2 * drivers/s390/char/tape_core.c
3 * basic function of the tape device driver
5 * S390 and zSeries version
6 * Copyright (C) 2001,2002 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Michael Holzheu <holzheu@de.ibm.com>
9 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
10 * Martin Schwidefsky <schwidefsky@de.ibm.com>
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/init.h> // for kernel parameters
16 #include <linux/kmod.h> // for requesting modules
17 #include <linux/spinlock.h> // for locks
18 #include <linux/vmalloc.h>
19 #include <linux/list.h>
21 #include <asm/types.h> // for variable types
26 #define PRINTK_HEADER "TAPE_CORE: "
28 static void __tape_do_irq (struct ccw_device *, unsigned long, struct irb *);
29 static void __tape_remove_request(struct tape_device *, struct tape_request *);
32 * One list to contain all tape devices of all disciplines, so
33 * we can assign the devices to minor numbers of the same major
34 * The list is protected by the rwlock
36 static struct list_head tape_device_list = LIST_HEAD_INIT(tape_device_list);
37 static rwlock_t tape_device_lock = RW_LOCK_UNLOCKED;
40 * Pointer to debug area.
42 debug_info_t *tape_dbf_area = NULL;
45 * Printable strings for tape enumerations.
47 const char *tape_state_verbose[TS_SIZE] =
49 [TS_UNUSED] = "UNUSED",
50 [TS_IN_USE] = "IN_USE",
51 [TS_BLKUSE] = "BLKUSE",
53 [TS_NOT_OPER] = "NOT_OP"
56 const char *tape_op_verbose[TO_SIZE] =
58 [TO_BLOCK] = "BLK", [TO_BSB] = "BSB",
59 [TO_BSF] = "BSF", [TO_DSE] = "DSE",
60 [TO_FSB] = "FSB", [TO_FSF] = "FSF",
61 [TO_LBL] = "LBL", [TO_NOP] = "NOP",
62 [TO_RBA] = "RBA", [TO_RBI] = "RBI",
63 [TO_RFO] = "RFO", [TO_REW] = "REW",
64 [TO_RUN] = "RUN", [TO_WRI] = "WRI",
65 [TO_WTM] = "WTM", [TO_MSEN] = "MSN",
66 [TO_LOAD] = "LOA", [TO_READ_CONFIG] = "RCF",
67 [TO_READ_ATTMSG] = "RAT",
68 [TO_DIS] = "DIS", [TO_ASSIGN] = "ASS",
73 * Some channel attached tape specific attributes.
75 * FIXME: In the future the first_minor and blocksize attribute should be
76 * replaced by a link to the cdev tree.
79 tape_medium_state_show(struct device *dev, char *buf)
81 struct tape_device *tdev;
83 tdev = (struct tape_device *) dev->driver_data;
84 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->medium_state);
88 DEVICE_ATTR(medium_state, 0444, tape_medium_state_show, NULL);
91 tape_first_minor_show(struct device *dev, char *buf)
93 struct tape_device *tdev;
95 tdev = (struct tape_device *) dev->driver_data;
96 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->first_minor);
100 DEVICE_ATTR(first_minor, 0444, tape_first_minor_show, NULL);
103 tape_state_show(struct device *dev, char *buf)
105 struct tape_device *tdev;
107 tdev = (struct tape_device *) dev->driver_data;
108 return scnprintf(buf, PAGE_SIZE, "%s\n", (tdev->first_minor < 0) ?
109 "OFFLINE" : tape_state_verbose[tdev->tape_state]);
113 DEVICE_ATTR(state, 0444, tape_state_show, NULL);
116 tape_operation_show(struct device *dev, char *buf)
118 struct tape_device *tdev;
121 tdev = (struct tape_device *) dev->driver_data;
122 if (tdev->first_minor < 0)
123 return scnprintf(buf, PAGE_SIZE, "N/A\n");
125 spin_lock_irq(get_ccwdev_lock(tdev->cdev));
126 if (list_empty(&tdev->req_queue))
127 rc = scnprintf(buf, PAGE_SIZE, "---\n");
129 struct tape_request *req;
131 req = list_entry(tdev->req_queue.next, struct tape_request,
133 rc = scnprintf(buf,PAGE_SIZE, "%s\n", tape_op_verbose[req->op]);
135 spin_unlock_irq(get_ccwdev_lock(tdev->cdev));
140 DEVICE_ATTR(operation, 0444, tape_operation_show, NULL);
143 tape_blocksize_show(struct device *dev, char *buf)
145 struct tape_device *tdev;
147 tdev = (struct tape_device *) dev->driver_data;
149 return scnprintf(buf, PAGE_SIZE, "%i\n", tdev->char_data.block_size);
153 DEVICE_ATTR(blocksize, 0444, tape_blocksize_show, NULL);
155 static struct attribute *tape_attrs[] = {
156 &dev_attr_medium_state.attr,
157 &dev_attr_first_minor.attr,
158 &dev_attr_state.attr,
159 &dev_attr_operation.attr,
160 &dev_attr_blocksize.attr,
164 static struct attribute_group tape_attr_group = {
169 * Tape state functions
172 tape_state_set(struct tape_device *device, enum tape_state newstate)
176 if (device->tape_state == TS_NOT_OPER) {
177 DBF_EVENT(3, "ts_set err: not oper\n");
180 DBF_EVENT(4, "ts. dev: %x\n", device->first_minor);
181 if (device->tape_state < TO_SIZE && device->tape_state >= 0)
182 str = tape_state_verbose[device->tape_state];
185 DBF_EVENT(4, "old ts: %s\n", str);
186 if (device->tape_state < TO_SIZE && device->tape_state >=0 )
187 str = tape_state_verbose[device->tape_state];
190 DBF_EVENT(4, "%s\n", str);
191 DBF_EVENT(4, "new ts:\t\n");
192 if (newstate < TO_SIZE && newstate >= 0)
193 str = tape_state_verbose[newstate];
196 DBF_EVENT(4, "%s\n", str);
197 device->tape_state = newstate;
198 wake_up(&device->state_change_wq);
202 tape_med_state_set(struct tape_device *device, enum tape_medium_state newstate)
204 if (device->medium_state == newstate)
208 device->tape_generic_status |= GMT_DR_OPEN(~0);
209 PRINT_INFO("(%s): Tape is unloaded\n",
210 device->cdev->dev.bus_id);
213 device->tape_generic_status &= ~GMT_DR_OPEN(~0);
214 PRINT_INFO("(%s): Tape has been mounted\n",
215 device->cdev->dev.bus_id);
221 device->medium_state = newstate;
222 wake_up(&device->state_change_wq);
226 * Stop running ccw. Has to be called with the device lock held.
229 __tape_halt_io(struct tape_device *device, struct tape_request *request)
234 /* Check if interrupt has already been processed */
235 if (request->callback == NULL)
239 for (retries = 0; retries < 5; retries++) {
241 rc = ccw_device_halt(device->cdev, (long) request);
243 rc = ccw_device_clear(device->cdev, (long) request);
245 if (rc == 0) { /* Termination successful */
247 request->status = TAPE_REQUEST_DONE;
252 DBF_EXCEPTION(2, "device gone, retry\n");
254 DBF_EXCEPTION(2, "I/O error, retry\n");
255 else if (rc == -EBUSY)
256 DBF_EXCEPTION(2, "device busy, retry late\n");
265 * Add device into the sorted list, giving it the first
266 * available minor number.
269 tape_assign_minor(struct tape_device *device)
271 struct tape_device *tmp;
275 write_lock(&tape_device_lock);
276 list_for_each_entry(tmp, &tape_device_list, node) {
277 if (minor < tmp->first_minor)
279 minor += TAPE_MINORS_PER_DEV;
282 write_unlock(&tape_device_lock);
285 device->first_minor = minor;
286 list_add_tail(&device->node, &tmp->node);
287 write_unlock(&tape_device_lock);
291 /* remove device from the list */
293 tape_remove_minor(struct tape_device *device)
295 write_lock(&tape_device_lock);
296 list_del_init(&device->node);
297 device->first_minor = -1;
298 write_unlock(&tape_device_lock);
305 tape_enable_device(struct tape_device *device,
306 struct tape_discipline *discipline)
310 DBF_LH(6, "tape_enable_device(%p, %p)\n", device, discipline);
312 if (device->tape_state != TS_INIT) {
313 DBF_LH(3, "Tapestate not INIT (%d)\n", device->tape_state);
317 /* Let the discipline have a go at the device. */
318 device->discipline = discipline;
319 rc = discipline->setup_device(device);
322 rc = tape_assign_minor(device);
326 rc = tapechar_setup_device(device);
329 rc = tapeblock_setup_device(device);
333 tape_state_set(device, TS_UNUSED);
337 tapechar_cleanup_device(device);
339 device->discipline->cleanup_device(device);
340 device->discipline = NULL;
342 tape_remove_minor(device);
348 * Disable tape device. Check if there is a running request and
349 * terminate it. Post all queued requests with -EIO.
352 tape_disable_device(struct tape_device *device)
354 struct list_head *l, *n;
355 struct tape_request *request;
357 spin_lock_irq(get_ccwdev_lock(device->cdev));
358 /* Post remaining requests with -EIO */
359 list_for_each_safe(l, n, &device->req_queue) {
360 request = list_entry(l, struct tape_request, list);
361 if (request->status == TAPE_REQUEST_IN_IO)
362 __tape_halt_io(device, request);
363 list_del(&request->list);
364 /* Decrease ref_count for removed request. */
365 request->device = tape_put_device(device);
367 if (request->callback != NULL)
368 request->callback(request, request->callback_data);
370 spin_unlock_irq(get_ccwdev_lock(device->cdev));
372 tapeblock_cleanup_device(device);
373 tapechar_cleanup_device(device);
374 device->discipline->cleanup_device(device);
375 tape_remove_minor(device);
377 tape_med_state_set(device, MS_UNKNOWN);
378 device->tape_state = TS_INIT;
382 * Allocate memory for a new device structure.
384 static struct tape_device *
385 tape_alloc_device(void)
387 struct tape_device *device;
389 device = (struct tape_device *)
390 kmalloc(sizeof(struct tape_device), GFP_KERNEL);
391 if (device == NULL) {
392 DBF_EXCEPTION(2, "ti:no mem\n");
393 PRINT_INFO ("can't allocate memory for "
394 "tape info structure\n");
395 return ERR_PTR(-ENOMEM);
397 memset(device, 0, sizeof(struct tape_device));
398 device->modeset_byte = (char *) kmalloc(1, GFP_KERNEL | GFP_DMA);
399 if (device->modeset_byte == NULL) {
400 DBF_EXCEPTION(2, "ti:no mem\n");
401 PRINT_INFO("can't allocate memory for modeset byte\n");
403 return ERR_PTR(-ENOMEM);
405 INIT_LIST_HEAD(&device->req_queue);
406 INIT_LIST_HEAD(&device->node);
407 init_waitqueue_head(&device->state_change_wq);
408 device->tape_state = TS_INIT;
409 device->medium_state = MS_UNKNOWN;
410 *device->modeset_byte = 0;
411 device->first_minor = -1;
412 atomic_set(&device->ref_count, 1);
418 * Get a reference to an existing device structure. This will automatically
419 * increment the reference count.
422 tape_get_device_reference(struct tape_device *device)
424 DBF_EVENT(4, "tape_get_device_reference(%p) = %i\n", device,
425 atomic_inc_return(&device->ref_count));
431 * Decrease the reference counter of a devices structure. If the
432 * reference counter reaches zero free the device structure.
433 * The function returns a NULL pointer to be used by the caller
434 * for clearing reference pointers.
437 tape_put_device(struct tape_device *device)
441 remain = atomic_dec_return(&device->ref_count);
443 DBF_EVENT(4, "tape_put_device(%p) -> %i\n", device, remain);
446 DBF_EVENT(4, "put device without reference\n");
447 PRINT_ERR("put device without reference\n");
449 DBF_EVENT(4, "tape_free_device(%p)\n", device);
450 kfree(device->modeset_byte);
459 * Find tape device by a device index.
462 tape_get_device(int devindex)
464 struct tape_device *device, *tmp;
466 device = ERR_PTR(-ENODEV);
467 read_lock(&tape_device_lock);
468 list_for_each_entry(tmp, &tape_device_list, node) {
469 if (tmp->first_minor / TAPE_MINORS_PER_DEV == devindex) {
470 device = tape_get_device_reference(tmp);
474 read_unlock(&tape_device_lock);
479 * Driverfs tape probe function.
482 tape_generic_probe(struct ccw_device *cdev)
484 struct tape_device *device;
485 char *bus_id = cdev->dev.bus_id;
487 device = tape_alloc_device();
490 PRINT_INFO("tape device %s found\n", bus_id);
491 cdev->dev.driver_data = device;
493 cdev->handler = __tape_do_irq;
495 ccw_device_set_options(cdev, CCWDEV_DO_PATHGROUP);
496 sysfs_create_group(&cdev->dev.kobj, &tape_attr_group);
502 * Driverfs tape remove function.
505 tape_generic_remove(struct ccw_device *cdev)
507 ccw_device_set_offline(cdev);
508 if (cdev->dev.driver_data != NULL) {
509 sysfs_remove_group(&cdev->dev.kobj, &tape_attr_group);
510 cdev->dev.driver_data = tape_put_device(cdev->dev.driver_data);
515 * Allocate a new tape ccw request
517 struct tape_request *
518 tape_alloc_request(int cplength, int datasize)
520 struct tape_request *request;
522 if (datasize > PAGE_SIZE || (cplength*sizeof(struct ccw1)) > PAGE_SIZE)
525 DBF_LH(6, "tape_alloc_request(%d, %d)\n", cplength, datasize);
527 request = (struct tape_request *) kmalloc(sizeof(struct tape_request),
529 if (request == NULL) {
530 DBF_EXCEPTION(1, "cqra nomem\n");
531 return ERR_PTR(-ENOMEM);
533 memset(request, 0, sizeof(struct tape_request));
534 /* allocate channel program */
536 request->cpaddr = kmalloc(cplength*sizeof(struct ccw1),
537 GFP_ATOMIC | GFP_DMA);
538 if (request->cpaddr == NULL) {
539 DBF_EXCEPTION(1, "cqra nomem\n");
541 return ERR_PTR(-ENOMEM);
543 memset(request->cpaddr, 0, cplength*sizeof(struct ccw1));
545 /* alloc small kernel buffer */
547 request->cpdata = kmalloc(datasize, GFP_KERNEL | GFP_DMA);
548 if (request->cpdata == NULL) {
549 DBF_EXCEPTION(1, "cqra nomem\n");
550 if (request->cpaddr != NULL)
551 kfree(request->cpaddr);
553 return ERR_PTR(-ENOMEM);
555 memset(request->cpdata, 0, datasize);
557 DBF_LH(6, "New request %p(%p/%p)\n", request, request->cpaddr,
564 * Free tape ccw request
567 tape_free_request (struct tape_request * request)
569 DBF_LH(6, "Free request %p\n", request);
571 if (request->device != NULL) {
572 request->device = tape_put_device(request->device);
574 if (request->cpdata != NULL)
575 kfree(request->cpdata);
576 if (request->cpaddr != NULL)
577 kfree(request->cpaddr);
582 __tape_do_io_list(struct tape_device *device)
584 struct list_head *l, *n;
585 struct tape_request *request;
588 DBF_LH(6, "__tape_do_io_list(%p)\n", device);
590 * Try to start each request on request queue until one is
591 * started successful.
593 list_for_each_safe(l, n, &device->req_queue) {
594 request = list_entry(l, struct tape_request, list);
595 #ifdef CONFIG_S390_TAPE_BLOCK
596 if (request->op == TO_BLOCK)
597 device->discipline->check_locate(device, request);
599 rc = ccw_device_start(device->cdev, request->cpaddr,
600 (unsigned long) request, 0x00,
603 request->status = TAPE_REQUEST_IN_IO;
606 /* Start failed. Remove request and indicate failure. */
607 DBF_EVENT(1, "tape: DOIO failed with er = %i\n", rc);
609 /* Set ending status and do callback. */
611 request->status = TAPE_REQUEST_DONE;
612 __tape_remove_request(device, request);
617 __tape_remove_request(struct tape_device *device, struct tape_request *request)
619 /* Remove from request queue. */
620 list_del(&request->list);
623 if (request->callback != NULL)
624 request->callback(request, request->callback_data);
626 /* Start next request. */
627 if (!list_empty(&device->req_queue))
628 __tape_do_io_list(device);
632 * Write sense data to console/dbf
635 tape_dump_sense(struct tape_device* device, struct tape_request *request,
640 PRINT_INFO("-------------------------------------------------\n");
641 PRINT_INFO("DSTAT : %02x CSTAT: %02x CPA: %04x\n",
642 irb->scsw.dstat, irb->scsw.cstat, irb->scsw.cpa);
643 PRINT_INFO("DEVICE: %s\n", device->cdev->dev.bus_id);
645 PRINT_INFO("OP : %s\n", tape_op_verbose[request->op]);
647 sptr = (unsigned int *) irb->ecw;
648 PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
649 sptr[0], sptr[1], sptr[2], sptr[3]);
650 PRINT_INFO("Sense data: %08X %08X %08X %08X \n",
651 sptr[4], sptr[5], sptr[6], sptr[7]);
652 PRINT_INFO("--------------------------------------------------\n");
656 * Write sense data to dbf
659 tape_dump_sense_dbf(struct tape_device *device, struct tape_request *request,
666 op = tape_op_verbose[request->op];
669 DBF_EVENT(3, "DSTAT : %02x CSTAT: %02x\n",
670 irb->scsw.dstat,irb->scsw.cstat);
671 DBF_EVENT(3, "DEVICE: %s OP\t: %s\n", device->cdev->dev.bus_id,op);
672 sptr = (unsigned int *) irb->ecw;
673 DBF_EVENT(3, "%08x %08x\n", sptr[0], sptr[1]);
674 DBF_EVENT(3, "%08x %08x\n", sptr[2], sptr[3]);
675 DBF_EVENT(3, "%08x %08x\n", sptr[4], sptr[5]);
676 DBF_EVENT(3, "%08x %08x\n", sptr[6], sptr[7]);
680 * I/O helper function. Adds the request to the request queue
681 * and starts it if the tape is idle. Has to be called with
682 * the device lock held.
685 __tape_do_io(struct tape_device *device, struct tape_request *request)
689 switch (request->op) {
694 if (device->tape_state == TS_INIT)
696 if (device->tape_state == TS_UNUSED)
699 if (device->tape_state == TS_BLKUSE)
701 if (device->tape_state != TS_IN_USE)
705 /* Increase use count of device for the added request. */
706 request->device = tape_get_device_reference(device);
708 if (list_empty(&device->req_queue)) {
709 /* No other requests are on the queue. Start this one. */
710 #ifdef CONFIG_S390_TAPE_BLOCK
711 if (request->op == TO_BLOCK)
712 device->discipline->check_locate(device, request);
714 rc = ccw_device_start(device->cdev, request->cpaddr,
715 (unsigned long) request, 0x00,
718 DBF_EVENT(1, "tape: DOIO failed with rc = %i\n", rc);
721 DBF_LH(5, "Request %p added for execution.\n", request);
722 list_add(&request->list, &device->req_queue);
723 request->status = TAPE_REQUEST_IN_IO;
725 DBF_LH(5, "Request %p add to queue.\n", request);
726 list_add_tail(&request->list, &device->req_queue);
727 request->status = TAPE_REQUEST_QUEUED;
733 * Add the request to the request queue, try to start it if the
734 * tape is idle. Return without waiting for end of i/o.
737 tape_do_io_async(struct tape_device *device, struct tape_request *request)
741 DBF_LH(6, "tape_do_io_async(%p, %p)\n", device, request);
743 spin_lock_irq(get_ccwdev_lock(device->cdev));
744 /* Add request to request queue and try to start it. */
745 rc = __tape_do_io(device, request);
746 spin_unlock_irq(get_ccwdev_lock(device->cdev));
751 * tape_do_io/__tape_wake_up
752 * Add the request to the request queue, try to start it if the
753 * tape is idle and wait uninterruptible for its completion.
756 __tape_wake_up(struct tape_request *request, void *data)
758 request->callback = NULL;
759 wake_up((wait_queue_head_t *) data);
763 tape_do_io(struct tape_device *device, struct tape_request *request)
765 wait_queue_head_t wq;
768 init_waitqueue_head(&wq);
769 spin_lock_irq(get_ccwdev_lock(device->cdev));
771 request->callback = __tape_wake_up;
772 request->callback_data = &wq;
773 /* Add request to request queue and try to start it. */
774 rc = __tape_do_io(device, request);
775 spin_unlock_irq(get_ccwdev_lock(device->cdev));
778 /* Request added to the queue. Wait for its completion. */
779 wait_event(wq, (request->callback == NULL));
780 /* Get rc from request */
785 * tape_do_io_interruptible/__tape_wake_up_interruptible
786 * Add the request to the request queue, try to start it if the
787 * tape is idle and wait uninterruptible for its completion.
790 __tape_wake_up_interruptible(struct tape_request *request, void *data)
792 request->callback = NULL;
793 wake_up_interruptible((wait_queue_head_t *) data);
797 tape_do_io_interruptible(struct tape_device *device,
798 struct tape_request *request)
800 wait_queue_head_t wq;
803 init_waitqueue_head(&wq);
804 spin_lock_irq(get_ccwdev_lock(device->cdev));
806 request->callback = __tape_wake_up_interruptible;
807 request->callback_data = &wq;
808 rc = __tape_do_io(device, request);
809 spin_unlock_irq(get_ccwdev_lock(device->cdev));
812 /* Request added to the queue. Wait for its completion. */
813 rc = wait_event_interruptible(wq, (request->callback == NULL));
814 if (rc != -ERESTARTSYS)
815 /* Request finished normally. */
817 /* Interrupted by a signal. We have to stop the current request. */
818 spin_lock_irq(get_ccwdev_lock(device->cdev));
819 rc = __tape_halt_io(device, request);
821 DBF_EVENT(3, "IO stopped on %s\n", device->cdev->dev.bus_id);
824 spin_unlock_irq(get_ccwdev_lock(device->cdev));
829 * Tape interrupt routine, called from the ccw_device layer
832 __tape_do_irq (struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
834 struct tape_device *device;
835 struct tape_request *request;
839 device = (struct tape_device *) cdev->dev.driver_data;
840 if (device == NULL) {
841 PRINT_ERR("could not get device structure for bus_id %s "
842 "in interrupt\n", cdev->dev.bus_id);
845 request = (struct tape_request *) intparm;
847 DBF_LH(6, "__tape_do_irq(device=%p, request=%p)\n", device, request);
849 /* May be an unsolicited irq */
851 request->rescnt = irb->scsw.count;
853 if (irb->scsw.dstat != 0x0c) {
854 /* Set the 'ONLINE' flag depending on sense byte 1 */
855 if(*(((__u8 *) irb->ecw) + 1) & SENSE_DRIVE_ONLINE)
856 device->tape_generic_status |= GMT_ONLINE(~0);
858 device->tape_generic_status &= ~GMT_ONLINE(~0);
861 * Any request that does not come back with channel end
862 * and device end is unusual. Log the sense data.
864 DBF_EVENT(3,"-- Tape Interrupthandler --\n");
865 tape_dump_sense_dbf(device, request, irb);
867 /* Upon normal completion the device _is_ online */
868 device->tape_generic_status |= GMT_ONLINE(~0);
870 if (device->tape_state == TS_NOT_OPER) {
871 DBF_EVENT(6, "tape:device is not operational\n");
876 * Request that were canceled still come back with an interrupt.
877 * To detect these request the state will be set to TAPE_REQUEST_DONE.
879 if(request != NULL && request->status == TAPE_REQUEST_DONE) {
880 __tape_remove_request(device, request);
884 rc = device->discipline->irq(device, request, irb);
886 * rc < 0 : request finished unsuccessfully.
887 * rc == TAPE_IO_SUCCESS: request finished successfully.
888 * rc == TAPE_IO_PENDING: request is still running. Ignore rc.
889 * rc == TAPE_IO_RETRY: request finished but needs another go.
890 * rc == TAPE_IO_STOP: request needs to get terminated.
894 case TAPE_IO_SUCCESS:
895 /* Upon normal completion the device _is_ online */
896 device->tape_generic_status |= GMT_ONLINE(~0);
899 case TAPE_IO_PENDING:
902 #ifdef CONFIG_S390_TAPE_BLOCK
903 if (request->op == TO_BLOCK)
904 device->discipline->check_locate(device, request);
906 rc = ccw_device_start(cdev, request->cpaddr,
907 (unsigned long) request, 0x00,
910 DBF_EVENT(1, "tape: DOIO failed with er = %i\n", rc);
915 __tape_halt_io(device, request);
919 DBF_EVENT(6, "xunknownrc\n");
920 PRINT_ERR("Invalid return code from discipline "
921 "interrupt function.\n");
928 /* May be an unsolicited irq */
929 if(request != NULL) {
930 /* Set ending status. */
932 request->status = TAPE_REQUEST_DONE;
933 __tape_remove_request(device, request);
935 __tape_do_io_list(device);
941 * Tape device open function used by tape_char & tape_block frontends.
944 tape_open(struct tape_device *device)
948 spin_lock(get_ccwdev_lock(device->cdev));
949 if (device->tape_state == TS_NOT_OPER) {
950 DBF_EVENT(6, "TAPE:nodev\n");
952 } else if (device->tape_state == TS_IN_USE) {
953 DBF_EVENT(6, "TAPE:dbusy\n");
955 } else if (device->tape_state == TS_BLKUSE) {
956 DBF_EVENT(6, "TAPE:dbusy\n");
958 } else if (device->discipline != NULL &&
959 !try_module_get(device->discipline->owner)) {
960 DBF_EVENT(6, "TAPE:nodisc\n");
963 tape_state_set(device, TS_IN_USE);
966 spin_unlock(get_ccwdev_lock(device->cdev));
971 * Tape device release function used by tape_char & tape_block frontends.
974 tape_release(struct tape_device *device)
976 spin_lock(get_ccwdev_lock(device->cdev));
977 if (device->tape_state == TS_IN_USE)
978 tape_state_set(device, TS_UNUSED);
979 module_put(device->discipline->owner);
980 spin_unlock(get_ccwdev_lock(device->cdev));
985 * Execute a magnetic tape command a number of times.
988 tape_mtop(struct tape_device *device, int mt_op, int mt_count)
993 DBF_EVENT(6, "TAPE:mtio\n");
994 DBF_EVENT(6, "TAPE:ioop: %x\n", mt_op);
995 DBF_EVENT(6, "TAPE:arg: %x\n", mt_count);
997 if (mt_op < 0 || mt_op >= TAPE_NR_MTOPS)
999 fn = device->discipline->mtop_array[mt_op];
1003 /* We assume that the backends can handle count up to 500. */
1004 if (mt_op == MTBSR || mt_op == MTFSR || mt_op == MTFSF ||
1005 mt_op == MTBSF || mt_op == MTFSFM || mt_op == MTBSFM) {
1007 for (; mt_count > 500; mt_count -= 500)
1008 if ((rc = fn(device, 500)) != 0)
1011 rc = fn(device, mt_count);
1013 rc = fn(device, mt_count);
1019 * Hutplug event support.
1022 tape_hotplug_event(struct tape_device *device, int devmaj, int action) {
1023 #ifdef CONFIG_HOTPLUG
1030 /* Call the busid DEVNO to be compatible with old tape.agent. */
1031 sprintf(busid, "DEVNO=%s", device->cdev->dev.bus_id);
1032 sprintf(major, "MAJOR=%d", devmaj);
1033 sprintf(minor, "MINOR=%d", device->first_minor);
1035 argv[0] = hotplug_path;
1040 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
1043 case TAPE_HOTPLUG_CHAR_ADD:
1044 case TAPE_HOTPLUG_BLOCK_ADD:
1045 envp[2] = "ACTION=add";
1047 case TAPE_HOTPLUG_CHAR_REMOVE:
1048 case TAPE_HOTPLUG_BLOCK_REMOVE:
1049 envp[2] = "ACTION=remove";
1055 case TAPE_HOTPLUG_CHAR_ADD:
1056 case TAPE_HOTPLUG_CHAR_REMOVE:
1057 envp[3] = "INTERFACE=char";
1059 case TAPE_HOTPLUG_BLOCK_ADD:
1060 case TAPE_HOTPLUG_BLOCK_REMOVE:
1061 envp[3] = "INTERFACE=block";
1071 call_usermodehelper(argv[0], argv, envp, 0);
1076 * Tape init function.
1081 tape_dbf_area = debug_register ( "tape", 1, 2, 4*sizeof(long));
1082 debug_register_view(tape_dbf_area, &debug_sprintf_view);
1083 #ifdef DBF_LIKE_HELL
1084 debug_set_level(tape_dbf_area, 6);
1086 DBF_EVENT(3, "tape init: ($Revision: 1.41 $)\n");
1094 * Tape exit function.
1099 DBF_EVENT(6, "tape exit\n");
1101 /* Get rid of the frontends */
1104 tape_proc_cleanup();
1105 debug_unregister (tape_dbf_area);
1108 MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte and "
1109 "Michael Holzheu (cotte@de.ibm.com,holzheu@de.ibm.com)");
1110 MODULE_DESCRIPTION("Linux on zSeries channel attached "
1111 "tape device driver ($Revision: 1.41 $)");
1112 MODULE_LICENSE("GPL");
1114 module_init(tape_init);
1115 module_exit(tape_exit);
1117 EXPORT_SYMBOL(tape_dbf_area);
1118 EXPORT_SYMBOL(tape_generic_remove);
1119 EXPORT_SYMBOL(tape_disable_device);
1120 EXPORT_SYMBOL(tape_generic_probe);
1121 EXPORT_SYMBOL(tape_enable_device);
1122 EXPORT_SYMBOL(tape_put_device);
1123 EXPORT_SYMBOL(tape_get_device_reference);
1124 EXPORT_SYMBOL(tape_state_verbose);
1125 EXPORT_SYMBOL(tape_op_verbose);
1126 EXPORT_SYMBOL(tape_state_set);
1127 EXPORT_SYMBOL(tape_med_state_set);
1128 EXPORT_SYMBOL(tape_alloc_request);
1129 EXPORT_SYMBOL(tape_free_request);
1130 EXPORT_SYMBOL(tape_dump_sense);
1131 EXPORT_SYMBOL(tape_dump_sense_dbf);
1132 EXPORT_SYMBOL(tape_do_io);
1133 EXPORT_SYMBOL(tape_do_io_async);
1134 EXPORT_SYMBOL(tape_do_io_interruptible);
1135 EXPORT_SYMBOL(tape_mtop);