2 /***********************************************************************
3 * drivers/s390/char/tape.c
4 * tape device driver for S/390 and zSeries tapes.
6 * S390 and zSeries version
7 * Copyright (C) 2001 IBM Corporation
8 * Author(s): Carsten Otte <cotte@de.ibm.com>
9 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
11 ***********************************************************************
16 #include <linux/config.h>
17 #include <linux/stddef.h>
18 #include <linux/kernel.h>
19 #include <linux/version.h>
20 #include <linux/proc_fs.h>
21 #include <linux/init.h>
22 #include <asm/types.h>
23 #include <asm/ccwcache.h>
24 #include <asm/idals.h>
25 #include <asm/ebcdic.h>
26 #include <linux/compatmac.h>
28 #include <linux/module.h>
30 #include <asm/debug.h>
31 #ifdef CONFIG_S390_TAPE_DYNAMIC
32 #include <asm/s390dyn.h>
35 #ifdef CONFIG_S390_TAPE_3490
38 #ifdef CONFIG_S390_TAPE_3480
41 #ifdef CONFIG_S390_TAPE_BLOCK
42 #include "tapeblock.h"
44 #ifdef CONFIG_S390_TAPE_CHAR
48 #include <linux/vmalloc.h>
50 #define PRINTK_HEADER "T390:"
53 /* state handling routines */
54 inline void tapestate_set (tape_info_t * ti, int newstate);
55 inline int tapestate_get (tape_info_t * ti);
56 void tapestate_event (tape_info_t * ti, int event);
59 tape_info_t *first_tape_info = NULL;
60 tape_discipline_t *first_discipline = NULL;
61 tape_frontend_t *first_frontend = NULL;
62 devreg_t* tape_devreg[128];
66 debug_info_t *tape_debug_area = NULL;
69 char* state_verbose[TS_SIZE]={
70 "TS_UNUSED", "TS_IDLE", "TS_DONE", "TS_FAILED",
90 "TS_REW_RELEASE_INIT",
105 char* event_verbose[TE_SIZE]= {
106 "TE_START", "TE_DONE", "TE_FAILED", "TE_ERROR", "TE_OTHER"};
108 /* our root devfs handle */
109 #ifdef CONFIG_DEVFS_FS
110 devfs_handle_t tape_devfs_root_entry;
113 tape_mkdevfsroots (tape_info_t* ti)
116 sprintf (devno,"%04x",ti->devinfo.devno);
117 ti->devfs_dir=devfs_mk_dir (tape_devfs_root_entry, devno, ti);
121 tape_rmdevfsroots (tape_info_t* ti)
123 devfs_unregister (ti->devfs_dir);
127 #ifdef CONFIG_PROC_FS
128 /* our proc tapedevices entry */
129 static struct proc_dir_entry *tape_devices_entry;
138 tape_devices_open (struct inode *inode, struct file *file)
142 tempinfo_t* tempinfo;
145 tempinfo = kmalloc (sizeof(tempinfo_t),GFP_KERNEL);
148 for (ti=first_tape_info;ti!=NULL;ti=ti->next)
149 size+=80; // FIXME: Guess better!
155 pos+=sprintf(data+pos,"TapeNo\tDevNo\tCuType\tCuModel\tDevType\tDevModel\tState\n");
156 for (ti=first_tape_info;ti!=NULL;ti=ti->next) {
157 pos+=sprintf(data+pos,"%d\t%04X\t%04X\t%02X\t%04X\t%02X\t\t%s\n",ti->rew_minor/2,
158 ti->devinfo.devno,ti->devinfo.sid_data.cu_type,
159 ti->devinfo.sid_data.cu_model,ti->devinfo.sid_data.dev_type,
160 ti->devinfo.sid_data.dev_model,((tapestate_get(ti) >= 0) &&
161 (tapestate_get(ti) < TS_SIZE)) ?
162 state_verbose[tapestate_get (ti)] : "TS UNKNOWN");
166 file->private_data= (void*) tempinfo;
174 tape_devices_read (struct file *file, char *user_buf, size_t user_len, loff_t * offset)
177 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
179 if (*offset >= p_info->len) {
182 len = user_len<(p_info->len - *offset)?user_len:(p_info->len - *offset);
183 if (copy_to_user (user_buf, &(p_info->data[*offset]), len))
186 return len; /* number of bytes "read" */
191 tape_devices_release (struct inode *inode, struct file *file)
194 tempinfo_t *p_info = (tempinfo_t *) file->private_data;
197 vfree (p_info->data);
206 static struct file_operations tape_devices_file_ops =
208 read:tape_devices_read, /* read */
209 open:tape_devices_open, /* open */
210 release:tape_devices_release, /* close */
213 static struct inode_operations tape_devices_inode_ops =
215 #if !(LINUX_VERSION_CODE > KERNEL_VERSION(2,3,98))
216 default_file_ops:&tape_devices_file_ops /* file ops */
217 #endif /* LINUX_IS_24 */
219 #endif /* CONFIG_PROC_FS */
221 /* SECTION: Parameters for tape */
222 char *tape[256] = { NULL, };
225 static char tape_parm_string[1024] __initdata = { 0, };
227 tape_split_parm_string (char *str)
231 while (tmp != NULL && *tmp != '\0') {
234 end = strchr (tmp, ',');
236 len = strlen (tmp) + 1;
238 len = (long) end - (long) tmp + 1;
242 tape[count] = kmalloc (len * sizeof (char), GFP_ATOMIC);
243 if (tape[count] == NULL) {
244 printk (KERN_WARNING PRINTK_HEADER
245 "can't store tape= parameter no %d\n",
249 memset (tape[count], 0, len * sizeof (char));
250 memcpy (tape[count], tmp, len * sizeof (char));
257 tape_parm_setup (char *str, int *ints)
259 int len = strlen (tape_parm_string);
261 strcat (tape_parm_string, ",");
263 strcat (tape_parm_string, str);
267 tape_parm_call_setup (char *str)
270 tape_parm_setup (str, &dummy);
274 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,2,16))
275 __setup("tape=", tape_parm_call_setup);
276 #endif /* kernel <2.2.19 */
277 #endif /* not defined MODULE */
280 tape_parm_strtoul (char *str, char **stra)
285 temp++; /* strip leading zero */
287 temp++; /* strip leading x */
289 val = simple_strtoul (temp, &temp, 16); /* interpret anything as hex */
294 static inline devreg_t *
295 tape_create_devreg (int devno)
297 devreg_t *devreg = kmalloc (sizeof (devreg_t), GFP_KERNEL);
298 if (devreg != NULL) {
299 memset (devreg, 0, sizeof (devreg_t));
300 devreg->ci.devno = devno;
301 devreg->flag = DEVREG_TYPE_DEVNO;
302 devreg->oper_func = tape_oper_handler;
308 tape_parm_parse (char **str)
311 int from, to,i,irq=0,rc,retries=0,tape_num=0;
312 s390_dev_info_t dinfo;
313 tape_info_t* ti,*tempti;
314 tape_discipline_t* disc;
317 /* no params present -> leave */
325 /* turn off autodetect mode, if any range is present */
326 from = tape_parm_strtoul (temp, &temp);
330 to = tape_parm_strtoul (temp, &temp);
332 for (i=from;i<=to;i++) {
334 // register for attch/detach of a devno
335 tape_devreg[devregct]=tape_create_devreg(i);
336 if (tape_devreg[devregct]==NULL) {
337 PRINT_WARN ("Could not create devreg for devno %04x, dyn. attach for this devno deactivated.\n",i);
339 s390_device_register (tape_devreg[devregct++]);
341 // we are activating a device if it is present
342 for (irq = get_irq_first(); irq!=-ENODEV; irq=get_irq_next(irq)) {
343 rc = get_dev_info_by_irq (irq, &dinfo);
345 disc = first_discipline;
346 while ((dinfo.devno == i) && (disc != NULL) && (disc->cu_type != dinfo.sid_data.cu_type))
347 disc = (tape_discipline_t *) (disc->next);
348 if ((disc == NULL) || (rc == -ENODEV) || (i!=dinfo.devno)) {
352 debug_text_event (tape_debug_area,3,"det irq: ");
353 debug_int_event (tape_debug_area,3,irq);
354 debug_text_event (tape_debug_area,3,"cu: ");
355 debug_int_event (tape_debug_area,3,disc->cu_type);
356 #endif /* TAPE_DEBUG */
357 PRINT_INFO ("using devno %04x with discipline %04x on irq %d as tape device %d\n",dinfo.devno,dinfo.sid_data.cu_type,irq,tape_num/2);
358 /* Allocate tape structure */
359 ti = kmalloc (sizeof (tape_info_t), GFP_ATOMIC);
362 debug_text_exception (tape_debug_area,3,"ti:no mem ");
363 #endif /* TAPE_DEBUG */
364 PRINT_INFO ("tape: can't allocate memory for "
365 "tape info structure\n");
368 memset(ti,0,sizeof(tape_info_t));
369 ti->discipline = disc;
371 rc = tape_setup (ti, irq, tape_num);
374 debug_text_event (tape_debug_area,3,"tsetup err");
375 debug_int_exception (tape_debug_area,3,rc);
376 #endif /* TAPE_DEBUG */
379 s390irq_spin_lock_irqsave (irq, lockflags);
380 if (first_tape_info == NULL) {
381 first_tape_info = ti;
383 tempti = first_tape_info;
384 while (tempti->next != NULL)
385 tempti = tempti->next;
388 s390irq_spin_unlock_irqrestore (irq, lockflags);
398 /* SECTION: Managing wrappers for ccwcache */
400 #define TAPE_EMERGENCY_REQUESTS 16
402 static ccw_req_t *tape_emergency_req[TAPE_EMERGENCY_REQUESTS] =
404 static spinlock_t tape_emergency_req_lock = SPIN_LOCK_UNLOCKED;
407 tape_init_emergency_req (void)
410 for (i = 0; i < TAPE_EMERGENCY_REQUESTS; i++) {
411 tape_emergency_req[i] = (ccw_req_t *) get_free_page (GFP_KERNEL);
415 #ifdef MODULE // We only cleanup the emergency requests on module unload.
417 tape_cleanup_emergency_req (void)
420 for (i = 0; i < TAPE_EMERGENCY_REQUESTS; i++) {
421 if (tape_emergency_req[i])
422 free_page ((long) (tape_emergency_req[i]));
424 printk (KERN_WARNING PRINTK_HEADER "losing one page for 'in-use' emergency request\n");
430 tape_alloc_request (char *magic, int cplength, int datasize)
432 ccw_req_t *rv = NULL;
434 if ((rv = ccw_alloc_request (magic, cplength, datasize)) != NULL) {
437 if (cplength * sizeof (ccw1_t) + datasize + sizeof (ccw_req_t) > PAGE_SIZE) {
440 spin_lock (&tape_emergency_req_lock);
441 for (i = 0; i < TAPE_EMERGENCY_REQUESTS; i++) {
442 if (tape_emergency_req[i] != NULL) {
443 rv = tape_emergency_req[i];
444 tape_emergency_req[i] = NULL;
447 spin_unlock (&tape_emergency_req_lock);
449 memset (rv, 0, PAGE_SIZE);
450 rv->cache = (kmem_cache_t *) (tape_emergency_req + i);
451 strncpy ((char *) (&rv->magic), magic, 4);
452 ASCEBC ((char *) (&rv->magic), 4);
453 rv->cplength = cplength;
454 rv->datasize = datasize;
455 rv->data = (void *) ((long) rv + PAGE_SIZE - datasize);
456 rv->cpaddr = (ccw1_t *) ((long) rv + sizeof (ccw_req_t));
462 tape_free_request (ccw_req_t * request)
464 if (request->cache >= (kmem_cache_t *) tape_emergency_req &&
465 request->cache <= (kmem_cache_t *) (tape_emergency_req + TAPE_EMERGENCY_REQUESTS)) {
466 *((ccw_req_t **) (request->cache)) = request;
468 clear_normalized_cda ((ccw1_t *) (request->cpaddr)); // avoid memory leak caused by modeset_byte
469 ccw_free_request (request);
474 * Allocate a ccw request and reserve it for tape driver
478 tape_alloc_ccw_req (tape_info_t * ti, int cplength, int datasize)
480 char tape_magic_id[] = "tape";
481 ccw_req_t *cqr = NULL;
485 cqr = tape_alloc_request (tape_magic_id, cplength, datasize);
489 PRINT_WARN ("empty CQR generated\n");
492 cqr->magic = TAPE_MAGIC; /* sets an identifier for tape driver */
493 cqr->device = ti; /* save pointer to tape info */
498 * Find the tape_info_t structure associated with irq
500 static inline tape_info_t *
501 tapedev_find_info (int irq)
505 ti = first_tape_info;
508 if (ti->devinfo.irq == irq)
510 } while ((ti = (tape_info_t *) ti->next) != NULL);
514 #define QUEUE_THRESHOLD 5
517 * Tape interrupt routine, called from Ingo's I/O layer
520 tape_irq (int irq, void *int_parm, struct pt_regs *regs)
522 tape_info_t *ti = tapedev_find_info (irq);
524 /* analyse devstat and fire event */
525 if (ti->devstat.dstat & DEV_STAT_UNIT_CHECK) {
526 tapestate_event (ti, TE_ERROR);
527 } else if (ti->devstat.dstat & (DEV_STAT_DEV_END)) {
528 tapestate_event (ti, TE_DONE);
530 tapestate_event (ti, TE_OTHER);
534 tape_oper_handler ( int irq, struct _devreg *dreg) {
535 tape_info_t* ti=first_tape_info;
536 tape_info_t* newtape;
537 int rc,tape_num,retries=0,i;
538 s390_dev_info_t dinfo;
539 tape_discipline_t* disc;
540 #ifdef CONFIG_DEVFS_FS
541 tape_frontend_t* frontend;
544 while ((ti!=NULL) && (ti->devinfo.irq!=irq))
547 // irq is (still) used by tape. tell ingo to try again later
548 PRINT_WARN ("Oper handler for irq %d called while irq still (internaly?) used.\n",irq);
551 // irq is not used by tape
552 rc = get_dev_info_by_irq (irq, &dinfo);
555 rc = get_dev_info_by_irq (irq, &dinfo);
557 PRINT_WARN ("No device information for new dev. could be retrieved.\n");
561 disc = first_discipline;
562 while ((disc != NULL) && (disc->cu_type != dinfo.sid_data.cu_type))
563 disc = (tape_discipline_t *) (disc->next);
565 PRINT_WARN ("No matching discipline for cu_type %x found, ignoring device %04x.\n",dinfo.sid_data.cu_type,dinfo.devno);
567 PRINT_WARN ("No device information for new dev. could be retrieved.\n");
568 if ((disc == NULL) || (rc == -ENODEV))
571 /* Allocate tape structure */
572 ti = kmalloc (sizeof (tape_info_t), GFP_ATOMIC);
574 PRINT_INFO ( "tape: can't allocate memory for "
575 "tape info structure\n");
578 memset(ti,0,sizeof(tape_info_t));
579 ti->discipline = disc;
583 // we have static device ranges, so fingure out the tape_num of the attached tape
584 for (i=0;i<devregct;i++)
585 if (tape_devreg[i]->ci.devno==dinfo.devno) {
590 // we are running in autoprobe mode, find a free tape_num
591 newtape=first_tape_info;
592 while (newtape!=NULL) {
593 if (newtape->rew_minor==tape_num) {
594 // tape num in use. try next one
596 newtape=first_tape_info;
598 // tape num not used by newtape. look at next tape info
599 newtape=newtape->next;
603 rc = tape_setup (ti, irq, tape_num);
608 #ifdef CONFIG_DEVFS_FS
609 for (frontend=first_frontend;frontend!=NULL;frontend=frontend->next)
610 frontend->mkdevfstree(ti);
612 s390irq_spin_lock_irqsave (irq,lockflags);
613 if (first_tape_info == NULL) {
614 first_tape_info = ti;
616 newtape = first_tape_info;
617 while (newtape->next != NULL)
618 newtape = newtape->next;
621 s390irq_spin_unlock_irqrestore (irq, lockflags);
627 tape_noper_handler ( int irq, int status ) {
628 tape_info_t *ti=first_tape_info;
630 #ifdef CONFIG_DEVFS_FS
631 tape_frontend_t *frontend;
634 s390irq_spin_lock_irqsave(irq,lockflags);
635 while (ti!=NULL && ti->devinfo.irq!=irq) ti=ti->next;
636 if (ti==NULL) return;
637 if (tapestate_get(ti)!=TS_UNUSED) {
639 PRINT_WARN ("Tape #%d was detached while it was busy. Expect errors!",ti->blk_minor/2);
640 tapestate_set(ti,TS_NOT_OPER);
643 switch (tapestate_get(ti)) {
644 case TS_REW_RELEASE_INIT:
645 tapestate_set(ti,TS_NOT_OPER);
648 #ifdef CONFIG_S390_TAPE_BLOCK
650 tapestate_set(ti,TS_NOT_OPER);
651 schedule_tapeblock_exec_IO(ti);
655 tapestate_set(ti,TS_NOT_OPER);
656 wake_up_interruptible (&ti->wq);
660 PRINT_WARN ("Tape #%d was detached.\n",ti->blk_minor/2);
661 if (ti==first_tape_info) {
662 first_tape_info=ti->next;
664 lastti=first_tape_info;
665 while (lastti->next!=ti) lastti=lastti->next;
666 lastti->next=ti->next;
668 #ifdef CONFIG_DEVFS_FS
669 for (frontend=first_frontend;frontend!=NULL;frontend=frontend->next)
670 frontend->rmdevfstree(ti);
671 tape_rmdevfsroots(ti);
675 s390irq_spin_unlock_irqrestore(irq,lockflags);
681 tape_dump_sense (devstat_t * stat)
688 PRINT_WARN ("------------I/O resulted in unit check:-----------\n");
689 for (sl = 0; sl < 4; sl++) {
690 PRINT_WARN ("Sense:");
691 for (sct = 0; sct < 8; sct++) {
692 PRINT_WARN (" %2d:0x%02X", 8 * sl + sct,
693 stat->ii.sense.data[8 * sl + sct]);
697 PRINT_INFO ("Sense data: %02X%02X%02X%02X %02X%02X%02X%02X "
698 " %02X%02X%02X%02X %02X%02X%02X%02X \n",
699 stat->ii.sense.data[0], stat->ii.sense.data[1],
700 stat->ii.sense.data[2], stat->ii.sense.data[3],
701 stat->ii.sense.data[4], stat->ii.sense.data[5],
702 stat->ii.sense.data[6], stat->ii.sense.data[7],
703 stat->ii.sense.data[8], stat->ii.sense.data[9],
704 stat->ii.sense.data[10], stat->ii.sense.data[11],
705 stat->ii.sense.data[12], stat->ii.sense.data[13],
706 stat->ii.sense.data[14], stat->ii.sense.data[15]);
707 PRINT_INFO ("Sense data: %02X%02X%02X%02X %02X%02X%02X%02X "
708 " %02X%02X%02X%02X %02X%02X%02X%02X \n",
709 stat->ii.sense.data[16], stat->ii.sense.data[17],
710 stat->ii.sense.data[18], stat->ii.sense.data[19],
711 stat->ii.sense.data[20], stat->ii.sense.data[21],
712 stat->ii.sense.data[22], stat->ii.sense.data[23],
713 stat->ii.sense.data[24], stat->ii.sense.data[25],
714 stat->ii.sense.data[26], stat->ii.sense.data[27],
715 stat->ii.sense.data[28], stat->ii.sense.data[29],
716 stat->ii.sense.data[30], stat->ii.sense.data[31]);
719 debug_text_event (tape_debug_area,3,"SENSE:");
720 for (sl=0;sl<31;sl++) {
721 debug_int_event (tape_debug_area,3,stat->ii.sense.data[sl]);
723 debug_int_exception (tape_debug_area,3,stat->ii.sense.data[31]);
728 * Setup tape_info_t structure of a tape device
731 tape_setup (tape_info_t * ti, int irq, int minor)
737 PRINT_WARN ("Device id %d on irq %d will not be accessible since this driver is restricted to 128 devices.\n",minor/2,irq);
740 rc = get_dev_info_by_irq (irq, &(ti->devinfo));
741 if (rc == -ENODEV) { /* end of device list */
744 ti->rew_minor = minor;
745 ti->nor_minor = minor + 1;
746 ti->blk_minor = minor;
747 #ifdef CONFIG_DEVFS_FS
748 tape_mkdevfsroots(ti);
751 #ifdef CONFIG_S390_TAPE_DYNAMIC
752 rc = s390_request_irq_special (irq, tape_irq, tape_noper_handler,0, "tape", &(ti->devstat));
754 rc = s390_request_irq (irq, tape_irq, 0, "tape", &(ti->devstat));
756 s390irq_spin_lock_irqsave (irq, lockflags);
759 PRINT_WARN ("Cannot register irq %d, rc=%d\n", irq, rc);
760 init_waitqueue_head (&ti->wq);
761 ti->kernbuf = ti->userbuf = ti->discdata = NULL;
762 tapestate_set (ti, TS_UNUSED);
764 ti->discipline->setup_assist (ti);
766 s390irq_spin_unlock_irqrestore (irq, lockflags);
771 * tape_init will register the driver for each tape.
777 s390_dev_info_t dinfo;
778 tape_discipline_t *disc;
779 tape_info_t *ti = NULL, *tempti = NULL;
780 char *opt_char,*opt_block,*opt_3490,*opt_3480;
781 int irq = 0, rc, retries = 0, tape_num = 0;
782 static int initialized=0;
784 if (initialized) // Only init the devices once
789 tape_debug_area = debug_register ( "tape", 3, 2, 10);
790 debug_register_view(tape_debug_area,&debug_hex_ascii_view);
791 debug_text_event (tape_debug_area,3,"begin init");
792 #endif /* TAPE_DEBUG */
795 PRINT_WARN ("IBM S/390 Tape Device Driver (v1.01).\n");
796 PRINT_WARN ("(C) IBM Deutschland Entwicklung GmbH, 2000\n");
797 opt_char=opt_block=opt_3480=opt_3490="not present";
798 #ifdef CONFIG_S390_TAPE_CHAR
801 #ifdef CONFIG_S390_TAPE_BLOCK
802 opt_block="built in";
804 #ifdef CONFIG_S390_TAPE_3480
807 #ifdef CONFIG_S390_TAPE_3490
810 /* print feature info */
811 PRINT_WARN ("character device frontend : %s\n",opt_char);
812 PRINT_WARN ("block device frontend : %s\n",opt_block);
813 PRINT_WARN ("support for 3480 compatible : %s\n",opt_3480);
814 PRINT_WARN ("support for 3490 compatible : %s\n",opt_3490);
817 tape_split_parm_string(tape_parm_string);
820 PRINT_INFO ("Using ranges supplied in parameters, disabling autoprobe mode.\n");
822 PRINT_INFO ("No parameters supplied, enabling autoprobe mode for all supported devices.\n");
823 #ifdef CONFIG_S390_TAPE_3490
825 first_discipline = tape3490_init (0); // no autoprobe for devices
827 first_discipline = tape3490_init (1); // do autoprobe since no parm specified
828 first_discipline->next = NULL;
831 #ifdef CONFIG_S390_TAPE_3480
832 if (first_discipline == NULL) {
834 first_discipline = tape3480_init (0); // no autoprobe for devices
836 first_discipline = tape3480_init (1); // do autoprobe since no parm specified
837 first_discipline->next = NULL;
840 first_discipline->next = tape3480_init (0); // no autoprobe for devices
842 first_discipline->next = tape3480_init (1); // do autoprobe since no parm specified
843 ((tape_discipline_t*) (first_discipline->next))->next=NULL;
846 #ifdef CONFIG_DEVFS_FS
847 tape_devfs_root_entry=devfs_mk_dir (NULL, "tape", NULL);
848 #endif CONFIG_DEVFS_FS
851 debug_text_event (tape_debug_area,3,"dev detect");
852 #endif /* TAPE_DEBUG */
853 /* Allocate the tape structures */
855 // we have parameters, continue with parsing the parameters and set the devices online
856 tape_parm_parse (tape);
858 // we are running in autodetect mode, search all devices for compatibles
859 for (irq = get_irq_first(); irq!=-ENODEV; irq=get_irq_next(irq)) {
860 rc = get_dev_info_by_irq (irq, &dinfo);
861 disc = first_discipline;
862 while ((disc != NULL) && (disc->cu_type != dinfo.sid_data.cu_type))
863 disc = (tape_discipline_t *) (disc->next);
864 if ((disc == NULL) || (rc == -ENODEV))
867 debug_text_event (tape_debug_area,3,"det irq: ");
868 debug_int_event (tape_debug_area,3,irq);
869 debug_text_event (tape_debug_area,3,"cu: ");
870 debug_int_event (tape_debug_area,3,disc->cu_type);
871 #endif /* TAPE_DEBUG */
872 PRINT_INFO ("using devno %04x with discipline %04x on irq %d as tape device %d\n",dinfo.devno,dinfo.sid_data.cu_type,irq,tape_num/2);
873 /* Allocate tape structure */
874 ti = kmalloc (sizeof (tape_info_t), GFP_ATOMIC);
877 debug_text_exception (tape_debug_area,3,"ti:no mem ");
878 #endif /* TAPE_DEBUG */
879 PRINT_INFO ("tape: can't allocate memory for "
880 "tape info structure\n");
883 memset(ti,0,sizeof(tape_info_t));
884 ti->discipline = disc;
886 rc = tape_setup (ti, irq, tape_num);
889 debug_text_event (tape_debug_area,3,"tsetup err");
890 debug_int_exception (tape_debug_area,3,rc);
891 #endif /* TAPE_DEBUG */
894 s390irq_spin_lock_irqsave (irq, lockflags);
895 if (first_tape_info == NULL) {
896 first_tape_info = ti;
898 tempti = first_tape_info;
899 while (tempti->next != NULL)
900 tempti = tempti->next;
904 s390irq_spin_unlock_irqrestore (irq, lockflags);
909 /* Allocate local buffer for the ccwcache */
910 tape_init_emergency_req ();
911 #ifdef CONFIG_PROC_FS
912 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,3,98))
913 tape_devices_entry = create_proc_entry ("tapedevices",
914 S_IFREG | S_IRUGO | S_IWUSR,
916 tape_devices_entry->proc_fops = &tape_devices_file_ops;
917 tape_devices_entry->proc_iops = &tape_devices_inode_ops;
919 tape_devices_entry = (struct proc_dir_entry *) kmalloc
920 (sizeof (struct proc_dir_entry), GFP_ATOMIC);
921 if (tape_devices_entry) {
922 memset (tape_devices_entry, 0, sizeof (struct proc_dir_entry));
923 tape_devices_entry->name = "tapedevices";
924 tape_devices_entry->namelen = strlen ("tapedevices");
925 tape_devices_entry->low_ino = 0;
926 tape_devices_entry->mode = (S_IFREG | S_IRUGO | S_IWUSR);
927 tape_devices_entry->nlink = 1;
928 tape_devices_entry->uid = 0;
929 tape_devices_entry->gid = 0;
930 tape_devices_entry->size = 0;
931 tape_devices_entry->get_info = NULL;
932 tape_devices_entry->ops = &tape_devices_inode_ops;
933 proc_register (&proc_root, tape_devices_entry);
936 #endif /* CONFIG_PROC_FS */
942 MODULE_AUTHOR("(C) 2001 IBM Deutschland Entwicklung GmbH by Carsten Otte (cotte@de.ibm.com)");
943 MODULE_DESCRIPTION("Linux for S/390 channel attached tape device driver");
944 MODULE_PARM (tape, "1-" __MODULE_STRING (256) "s");
949 #ifdef CONFIG_S390_TAPE_CHAR
952 #ifdef CONFIG_S390_TAPE_BLOCK
959 cleanup_module (void)
961 tape_info_t *ti ,*temp;
962 tape_frontend_t* frontend, *tempfe;
963 tape_discipline_t* disc ,*tempdi;
966 debug_text_event (tape_debug_area,6,"cleaup mod");
967 #endif /* TAPE_DEBUG */
970 // we are running with parameters. we'll now deregister from our devno's
971 for (i=0;i<devregct;i++) {
972 s390_device_unregister(tape_devreg[devregct]);
975 ti = first_tape_info;
981 debug_text_event (tape_debug_area,6,"free irq:");
982 debug_int_event (tape_debug_area,6,temp->devinfo.irq);
983 #endif /* TAPE_DEBUG */
984 free_irq (temp->devinfo.irq, &(temp->devstat));
985 if (temp->discdata) kfree (temp->discdata);
986 if (temp->kernbuf) kfree (temp->kernbuf);
987 if (temp->cqr) tape_free_request(temp->cqr);
988 #ifdef CONFIG_DEVFS_FS
989 for (frontend=first_frontend;frontend!=NULL;frontend=frontend->next)
990 frontend->rmdevfstree(temp);
991 tape_rmdevfsroots(temp);
995 #ifdef CONFIG_DEVFS_FS
996 devfs_unregister (tape_devfs_root_entry);
997 #endif CONFIG_DEVFS_FS
998 #ifdef CONFIG_PROC_FS
999 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,3,98))
1000 remove_proc_entry ("tapedevices", &proc_root);
1002 proc_unregister (&proc_root, tape_devices_entry->low_ino);
1003 kfree (tape_devices_entry);
1004 #endif /* LINUX_IS_24 */
1006 #ifdef CONFIG_S390_TAPE_CHAR
1009 #ifdef CONFIG_S390_TAPE_BLOCK
1012 frontend=first_frontend;
1013 while (frontend != NULL) {
1015 frontend = frontend->next;
1018 disc=first_discipline;
1019 while (disc != NULL) {
1028 /* Deallocate the local buffer for the ccwcache */
1029 tape_cleanup_emergency_req ();
1031 debug_unregister (tape_debug_area);
1032 #endif /* TAPE_DEBUG */
1037 tapestate_set (tape_info_t * ti, int newstate)
1039 if (ti->tape_state == TS_NOT_OPER) {
1041 debug_text_event (tape_debug_area,3,"ts_set err");
1042 debug_text_exception (tape_debug_area,3,"dev n.oper");
1043 #endif /* TAPE_DEBUG */
1046 debug_text_event (tape_debug_area,4,"ts. dev: ");
1047 debug_int_event (tape_debug_area,4,ti->blk_minor);
1048 debug_text_event (tape_debug_area,4,"old ts: ");
1049 debug_text_event (tape_debug_area,4,(((tapestate_get (ti) < TS_SIZE) &&
1050 (tapestate_get (ti) >=0 )) ?
1051 state_verbose[tapestate_get (ti)] :
1053 debug_text_event (tape_debug_area,4,"new ts: ");
1054 debug_text_event (tape_debug_area,4,(((newstate < TS_SIZE) &&
1056 state_verbose[newstate] :
1058 #endif /* TAPE_DEBUG */
1059 ti->tape_state = newstate;
1064 tapestate_get (tape_info_t * ti)
1066 return (ti->tape_state);
1070 tapestate_event (tape_info_t * ti, int event)
1073 debug_text_event (tape_debug_area,6,"te! dev: ");
1074 debug_int_event (tape_debug_area,6,ti->blk_minor);
1075 debug_text_event (tape_debug_area,6,"event:");
1076 debug_text_event (tape_debug_area,6,((event >=0) &&
1077 (event < TE_SIZE)) ?
1078 event_verbose[event] : "TE UNKNOWN");
1079 debug_text_event (tape_debug_area,6,"state:");
1080 debug_text_event (tape_debug_area,6,((tapestate_get(ti) >= 0) &&
1081 (tapestate_get(ti) < TS_SIZE)) ?
1082 state_verbose[tapestate_get (ti)] :
1084 #endif /* TAPE_DEBUG */
1085 if (event == TE_ERROR) {
1086 ti->discipline->error_recovery(ti);
1089 (event < TE_SIZE) &&
1090 (tapestate_get (ti) >= 0) &&
1091 (tapestate_get (ti) < TS_SIZE) &&
1092 ((*(ti->discipline->event_table))[tapestate_get (ti)][event] != NULL))
1093 ((*(ti->discipline->event_table))[tapestate_get (ti)][event]) (ti);
1096 debug_text_exception (tape_debug_area,3,"TE UNEXPEC");
1097 #endif /* TAPE_DEBUG */
1098 ti->discipline->default_handler (ti);
1104 * Overrides for Emacs so that we follow Linus's tabbing style.
1105 * Emacs will notice this stuff at the end of the file and automatically
1106 * adjust the settings for this buffer only. This must remain at the end
1108 * ---------------------------------------------------------------------------
1111 * c-brace-imaginary-offset: 0
1112 * c-brace-offset: -4
1113 * c-argdecl-indent: 4
1114 * c-label-offset: -4
1115 * c-continued-statement-offset: 4
1116 * c-continued-brace-offset: 0
1117 * indent-tabs-mode: nil