2 * SCSI Media Changer device driver for Linux 2.6
4 * (c) 1996-2003 Gerd Knorr <kraxel@bytesex.org>
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/sched.h>
17 #include <linux/major.h>
18 #include <linux/string.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <linux/blkdev.h>
22 #include <linux/completion.h>
23 #include <linux/ioctl32.h>
24 #include <linux/compat.h>
25 #include <linux/chio.h> /* here are all the ioctls */
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_cmnd.h>
29 #include <scsi/scsi_driver.h>
30 #include <scsi/scsi_ioctl.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_device.h>
33 #include <scsi/scsi_eh.h>
34 #include <scsi/scsi_dbg.h>
39 MODULE_DESCRIPTION("device driver for scsi media changer devices");
40 MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org>");
41 MODULE_LICENSE("GPL");
44 module_param(init
, int, 0444);
45 MODULE_PARM_DESC(init
, \
46 "initialize element status on driver load (default: on)");
48 static int timeout_move
= 300;
49 module_param(timeout_move
, int, 0644);
50 MODULE_PARM_DESC(timeout_move
,"timeout for move commands "
51 "(default: 300 seconds)");
53 static int timeout_init
= 3600;
54 module_param(timeout_init
, int, 0644);
55 MODULE_PARM_DESC(timeout_init
,"timeout for INITIALIZE ELEMENT STATUS "
56 "(default: 3600 seconds)");
58 static int verbose
= 1;
59 module_param(verbose
, int, 0644);
60 MODULE_PARM_DESC(verbose
,"be verbose (default: on)");
63 module_param(debug
, int, 0644);
64 MODULE_PARM_DESC(debug
,"enable/disable debug messages, also prints more "
65 "detailed sense codes on scsi errors (default: off)");
67 static int dt_id
[CH_DT_MAX
] = { [ 0 ... (CH_DT_MAX
-1) ] = -1 };
68 static int dt_lun
[CH_DT_MAX
];
69 module_param_array(dt_id
, int, NULL
, 0444);
70 module_param_array(dt_lun
, int, NULL
, 0444);
72 /* tell the driver about vendor-specific slots */
73 static int vendor_firsts
[CH_TYPES
-4];
74 static int vendor_counts
[CH_TYPES
-4];
75 module_param_array(vendor_firsts
, int, NULL
, 0444);
76 module_param_array(vendor_counts
, int, NULL
, 0444);
78 static char *vendor_labels
[CH_TYPES
-4] = {
79 "v0", "v1", "v2", "v3"
81 // module_param_string_array(vendor_labels, NULL, 0444);
83 #define dprintk(fmt, arg...) if (debug) \
84 printk(KERN_DEBUG "%s: " fmt, ch->name , ## arg)
85 #define vprintk(fmt, arg...) if (verbose) \
86 printk(KERN_INFO "%s: " fmt, ch->name , ## arg)
88 /* ------------------------------------------------------------------- */
92 static int ch_probe(struct device
*);
93 static int ch_remove(struct device
*);
94 static int ch_open(struct inode
* inode
, struct file
* filp
);
95 static int ch_release(struct inode
* inode
, struct file
* filp
);
96 static int ch_ioctl(struct inode
* inode
, struct file
* filp
,
97 unsigned int cmd
, unsigned long arg
);
99 static long ch_ioctl_compat(struct file
* filp
,
100 unsigned int cmd
, unsigned long arg
);
103 static struct class * ch_sysfs_class
;
106 struct list_head list
;
109 struct scsi_device
*device
;
110 struct scsi_device
**dt
; /* ptrs to data transfer elements */
111 u_int firsts
[CH_TYPES
];
112 u_int counts
[CH_TYPES
];
113 u_int unit_attention
;
115 struct semaphore lock
;
118 static LIST_HEAD(ch_devlist
);
119 static spinlock_t ch_devlist_lock
= SPIN_LOCK_UNLOCKED
;
120 static int ch_devcount
;
122 static struct scsi_driver ch_template
=
124 .owner
= THIS_MODULE
,
132 static struct file_operations changer_fops
=
134 .owner
= THIS_MODULE
,
136 .release
= ch_release
,
139 .compat_ioctl
= ch_ioctl_compat
,
149 /* Just filled in what looks right. Hav'nt checked any standard paper for
150 these errno assignments, so they may be wrong... */
152 .sense
= ILLEGAL_REQUEST
,
155 .errno
= EBADSLT
, /* Invalid element address */
157 .sense
= ILLEGAL_REQUEST
,
160 .errno
= EBADE
, /* Import or export element accessed */
162 .sense
= ILLEGAL_REQUEST
,
165 .errno
= EXFULL
, /* Medium destination element full */
167 .sense
= ILLEGAL_REQUEST
,
170 .errno
= EBADE
, /* Medium source element empty */
172 .sense
= ILLEGAL_REQUEST
,
175 .errno
= EBADRQC
, /* Invalid command operation code */
181 /* ------------------------------------------------------------------- */
183 static int ch_find_errno(struct scsi_sense_hdr
*sshdr
)
187 /* Check to see if additional sense information is available */
188 if (scsi_sense_valid(sshdr
) &&
190 for (i
= 0; err
[i
].errno
!= 0; i
++) {
191 if (err
[i
].sense
== sshdr
->sense_key
&&
192 err
[i
].asc
== sshdr
->asc
&&
193 err
[i
].ascq
== sshdr
->ascq
) {
194 errno
= -err
[i
].errno
;
205 ch_do_scsi(scsi_changer
*ch
, unsigned char *cmd
,
206 void *buffer
, unsigned buflength
,
207 enum dma_data_direction direction
)
209 int errno
, retries
= 0, timeout
, result
;
210 struct scsi_sense_hdr sshdr
;
212 timeout
= (cmd
[0] == INITIALIZE_ELEMENT_STATUS
)
213 ? timeout_init
: timeout_move
;
218 dprintk("command: ");
219 __scsi_print_command(cmd
);
222 result
= scsi_execute_req(ch
->device
, cmd
, direction
, buffer
,
223 buflength
, &sshdr
, timeout
* HZ
,
226 dprintk("result: 0x%x\n",result
);
227 if (driver_byte(result
) & DRIVER_SENSE
) {
229 scsi_print_sense_hdr(ch
->name
, &sshdr
);
230 errno
= ch_find_errno(&sshdr
);
232 switch(sshdr
.sense_key
) {
234 ch
->unit_attention
= 1;
243 /* ------------------------------------------------------------------------ */
246 ch_elem_to_typecode(scsi_changer
*ch
, u_int elem
)
250 for (i
= 0; i
< CH_TYPES
; i
++) {
251 if (elem
>= ch
->firsts
[i
] &&
252 elem
< ch
->firsts
[i
] +
260 ch_read_element_status(scsi_changer
*ch
, u_int elem
, char *data
)
266 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
271 memset(cmd
,0,sizeof(cmd
));
272 cmd
[0] = READ_ELEMENT_STATUS
;
273 cmd
[1] = (ch
->device
->lun
<< 5) |
274 (ch
->voltags
? 0x10 : 0) |
275 ch_elem_to_typecode(ch
,elem
);
276 cmd
[2] = (elem
>> 8) & 0xff;
277 cmd
[3] = elem
& 0xff;
280 if (0 == (result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_FROM_DEVICE
))) {
281 if (((buffer
[16] << 8) | buffer
[17]) != elem
) {
282 dprintk("asked for element 0x%02x, got 0x%02x\n",
283 elem
,(buffer
[16] << 8) | buffer
[17]);
287 memcpy(data
,buffer
+16,16);
291 vprintk("device has no volume tag support\n");
294 dprintk("READ ELEMENT STATUS for element 0x%x failed\n",elem
);
301 ch_init_elem(scsi_changer
*ch
)
306 vprintk("INITIALIZE ELEMENT STATUS, may take some time ...\n");
307 memset(cmd
,0,sizeof(cmd
));
308 cmd
[0] = INITIALIZE_ELEMENT_STATUS
;
309 cmd
[1] = ch
->device
->lun
<< 5;
310 err
= ch_do_scsi(ch
, cmd
, NULL
, 0, DMA_NONE
);
311 vprintk("... finished\n");
316 ch_readconfig(scsi_changer
*ch
)
318 u_char cmd
[10], data
[16];
323 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
326 memset(buffer
,0,512);
328 memset(cmd
,0,sizeof(cmd
));
330 cmd
[1] = ch
->device
->lun
<< 5;
333 result
= ch_do_scsi(ch
, cmd
, buffer
, 255, DMA_FROM_DEVICE
);
336 result
= ch_do_scsi(ch
, cmd
, buffer
, 255, DMA_FROM_DEVICE
);
339 ch
->firsts
[CHET_MT
] =
340 (buffer
[buffer
[3]+ 6] << 8) | buffer
[buffer
[3]+ 7];
341 ch
->counts
[CHET_MT
] =
342 (buffer
[buffer
[3]+ 8] << 8) | buffer
[buffer
[3]+ 9];
343 ch
->firsts
[CHET_ST
] =
344 (buffer
[buffer
[3]+10] << 8) | buffer
[buffer
[3]+11];
345 ch
->counts
[CHET_ST
] =
346 (buffer
[buffer
[3]+12] << 8) | buffer
[buffer
[3]+13];
347 ch
->firsts
[CHET_IE
] =
348 (buffer
[buffer
[3]+14] << 8) | buffer
[buffer
[3]+15];
349 ch
->counts
[CHET_IE
] =
350 (buffer
[buffer
[3]+16] << 8) | buffer
[buffer
[3]+17];
351 ch
->firsts
[CHET_DT
] =
352 (buffer
[buffer
[3]+18] << 8) | buffer
[buffer
[3]+19];
353 ch
->counts
[CHET_DT
] =
354 (buffer
[buffer
[3]+20] << 8) | buffer
[buffer
[3]+21];
355 vprintk("type #1 (mt): 0x%x+%d [medium transport]\n",
357 ch
->counts
[CHET_MT
]);
358 vprintk("type #2 (st): 0x%x+%d [storage]\n",
360 ch
->counts
[CHET_ST
]);
361 vprintk("type #3 (ie): 0x%x+%d [import/export]\n",
363 ch
->counts
[CHET_IE
]);
364 vprintk("type #4 (dt): 0x%x+%d [data transfer]\n",
366 ch
->counts
[CHET_DT
]);
368 vprintk("reading element address assigment page failed!\n");
371 /* vendor specific element types */
372 for (i
= 0; i
< 4; i
++) {
373 if (0 == vendor_counts
[i
])
375 if (NULL
== vendor_labels
[i
])
377 ch
->firsts
[CHET_V1
+i
] = vendor_firsts
[i
];
378 ch
->counts
[CHET_V1
+i
] = vendor_counts
[i
];
379 vprintk("type #%d (v%d): 0x%x+%d [%s, vendor specific]\n",
380 i
+5,i
+1,vendor_firsts
[i
],vendor_counts
[i
],
384 /* look up the devices of the data transfer elements */
385 ch
->dt
= kmalloc(ch
->counts
[CHET_DT
]*sizeof(struct scsi_device
),
387 for (elem
= 0; elem
< ch
->counts
[CHET_DT
]; elem
++) {
390 if (elem
< CH_DT_MAX
&& -1 != dt_id
[elem
]) {
393 vprintk("dt 0x%x: [insmod option] ",
394 elem
+ch
->firsts
[CHET_DT
]);
395 } else if (0 != ch_read_element_status
396 (ch
,elem
+ch
->firsts
[CHET_DT
],data
)) {
397 vprintk("dt 0x%x: READ ELEMENT STATUS failed\n",
398 elem
+ch
->firsts
[CHET_DT
]);
400 vprintk("dt 0x%x: ",elem
+ch
->firsts
[CHET_DT
]);
401 if (data
[6] & 0x80) {
403 printk("not this SCSI bus\n");
405 } else if (0 == (data
[6] & 0x30)) {
407 printk("ID/LUN unknown\n");
412 if (data
[6] & 0x20) id
= data
[7];
413 if (data
[6] & 0x10) lun
= data
[6] & 7;
418 printk("ID %i, LUN %i, ",id
,lun
);
420 scsi_device_lookup(ch
->device
->host
,
424 /* should not happen */
426 printk("Huh? device not found!\n");
429 printk("name: %8.8s %16.16s %4.4s\n",
430 ch
->dt
[elem
]->vendor
,
442 /* ------------------------------------------------------------------------ */
445 ch_position(scsi_changer
*ch
, u_int trans
, u_int elem
, int rotate
)
449 dprintk("position: 0x%x\n",elem
);
451 trans
= ch
->firsts
[CHET_MT
];
452 memset(cmd
,0,sizeof(cmd
));
453 cmd
[0] = POSITION_TO_ELEMENT
;
454 cmd
[1] = ch
->device
->lun
<< 5;
455 cmd
[2] = (trans
>> 8) & 0xff;
456 cmd
[3] = trans
& 0xff;
457 cmd
[4] = (elem
>> 8) & 0xff;
458 cmd
[5] = elem
& 0xff;
459 cmd
[8] = rotate
? 1 : 0;
460 return ch_do_scsi(ch
, cmd
, NULL
, 0, DMA_NONE
);
464 ch_move(scsi_changer
*ch
, u_int trans
, u_int src
, u_int dest
, int rotate
)
468 dprintk("move: 0x%x => 0x%x\n",src
,dest
);
470 trans
= ch
->firsts
[CHET_MT
];
471 memset(cmd
,0,sizeof(cmd
));
472 cmd
[0] = MOVE_MEDIUM
;
473 cmd
[1] = ch
->device
->lun
<< 5;
474 cmd
[2] = (trans
>> 8) & 0xff;
475 cmd
[3] = trans
& 0xff;
476 cmd
[4] = (src
>> 8) & 0xff;
478 cmd
[6] = (dest
>> 8) & 0xff;
479 cmd
[7] = dest
& 0xff;
480 cmd
[10] = rotate
? 1 : 0;
481 return ch_do_scsi(ch
, cmd
, NULL
,0, DMA_NONE
);
485 ch_exchange(scsi_changer
*ch
, u_int trans
, u_int src
,
486 u_int dest1
, u_int dest2
, int rotate1
, int rotate2
)
490 dprintk("exchange: 0x%x => 0x%x => 0x%x\n",
493 trans
= ch
->firsts
[CHET_MT
];
494 memset(cmd
,0,sizeof(cmd
));
495 cmd
[0] = EXCHANGE_MEDIUM
;
496 cmd
[1] = ch
->device
->lun
<< 5;
497 cmd
[2] = (trans
>> 8) & 0xff;
498 cmd
[3] = trans
& 0xff;
499 cmd
[4] = (src
>> 8) & 0xff;
501 cmd
[6] = (dest1
>> 8) & 0xff;
502 cmd
[7] = dest1
& 0xff;
503 cmd
[8] = (dest2
>> 8) & 0xff;
504 cmd
[9] = dest2
& 0xff;
505 cmd
[10] = (rotate1
? 1 : 0) | (rotate2
? 2 : 0);
507 return ch_do_scsi(ch
, cmd
, NULL
,0, DMA_NONE
);
511 ch_check_voltag(char *tag
)
515 for (i
= 0; i
< 32; i
++) {
516 /* restrict to ascii */
517 if (tag
[i
] >= 0x7f || tag
[i
] < 0x20)
519 /* don't allow search wildcards */
527 ch_set_voltag(scsi_changer
*ch
, u_int elem
,
528 int alternate
, int clear
, u_char
*tag
)
534 buffer
= kmalloc(512, GFP_KERNEL
);
537 memset(buffer
,0,512);
539 dprintk("%s %s voltag: 0x%x => \"%s\"\n",
540 clear
? "clear" : "set",
541 alternate
? "alternate" : "primary",
543 memset(cmd
,0,sizeof(cmd
));
544 cmd
[0] = SEND_VOLUME_TAG
;
545 cmd
[1] = (ch
->device
->lun
<< 5) |
546 ch_elem_to_typecode(ch
,elem
);
547 cmd
[2] = (elem
>> 8) & 0xff;
548 cmd
[3] = elem
& 0xff;
550 ? (alternate
? 0x0d : 0x0c)
551 : (alternate
? 0x0b : 0x0a);
555 memcpy(buffer
,tag
,32);
556 ch_check_voltag(buffer
);
558 result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_TO_DEVICE
);
563 static int ch_gstatus(scsi_changer
*ch
, int type
, unsigned char *dest
)
570 for (i
= 0; i
< ch
->counts
[type
]; i
++) {
571 if (0 != ch_read_element_status
572 (ch
, ch
->firsts
[type
]+i
,data
)) {
576 put_user(data
[2], dest
+i
);
577 if (data
[2] & CESTATUS_EXCEPT
)
578 vprintk("element 0x%x: asc=0x%x, ascq=0x%x\n",
580 (int)data
[4],(int)data
[5]);
581 retval
= ch_read_element_status
582 (ch
, ch
->firsts
[type
]+i
,data
);
590 /* ------------------------------------------------------------------------ */
593 ch_release(struct inode
*inode
, struct file
*file
)
595 scsi_changer
*ch
= file
->private_data
;
597 scsi_device_put(ch
->device
);
598 file
->private_data
= NULL
;
603 ch_open(struct inode
*inode
, struct file
*file
)
605 scsi_changer
*tmp
, *ch
;
606 int minor
= iminor(inode
);
608 spin_lock(&ch_devlist_lock
);
610 list_for_each_entry(tmp
,&ch_devlist
,list
) {
611 if (tmp
->minor
== minor
)
614 if (NULL
== ch
|| scsi_device_get(ch
->device
)) {
615 spin_unlock(&ch_devlist_lock
);
618 spin_unlock(&ch_devlist_lock
);
620 file
->private_data
= ch
;
625 ch_checkrange(scsi_changer
*ch
, unsigned int type
, unsigned int unit
)
627 if (type
>= CH_TYPES
|| unit
>= ch
->counts
[type
])
632 static int ch_ioctl(struct inode
* inode
, struct file
* file
,
633 unsigned int cmd
, unsigned long arg
)
635 scsi_changer
*ch
= file
->private_data
;
641 struct changer_params params
;
643 params
.cp_curpicker
= 0;
644 params
.cp_npickers
= ch
->counts
[CHET_MT
];
645 params
.cp_nslots
= ch
->counts
[CHET_ST
];
646 params
.cp_nportals
= ch
->counts
[CHET_IE
];
647 params
.cp_ndrives
= ch
->counts
[CHET_DT
];
649 if (copy_to_user((void *) arg
, ¶ms
, sizeof(params
)))
655 struct changer_vendor_params vparams
;
657 memset(&vparams
,0,sizeof(vparams
));
658 if (ch
->counts
[CHET_V1
]) {
659 vparams
.cvp_n1
= ch
->counts
[CHET_V1
];
660 strncpy(vparams
.cvp_label1
,vendor_labels
[0],16);
662 if (ch
->counts
[CHET_V2
]) {
663 vparams
.cvp_n2
= ch
->counts
[CHET_V2
];
664 strncpy(vparams
.cvp_label2
,vendor_labels
[1],16);
666 if (ch
->counts
[CHET_V3
]) {
667 vparams
.cvp_n3
= ch
->counts
[CHET_V3
];
668 strncpy(vparams
.cvp_label3
,vendor_labels
[2],16);
670 if (ch
->counts
[CHET_V4
]) {
671 vparams
.cvp_n4
= ch
->counts
[CHET_V4
];
672 strncpy(vparams
.cvp_label4
,vendor_labels
[3],16);
674 if (copy_to_user((void *) arg
, &vparams
, sizeof(vparams
)))
681 struct changer_position pos
;
683 if (copy_from_user(&pos
, (void*)arg
, sizeof (pos
)))
686 if (0 != ch_checkrange(ch
, pos
.cp_type
, pos
.cp_unit
)) {
687 dprintk("CHIOPOSITION: invalid parameter\n");
691 retval
= ch_position(ch
,0,
692 ch
->firsts
[pos
.cp_type
] + pos
.cp_unit
,
693 pos
.cp_flags
& CP_INVERT
);
700 struct changer_move mv
;
702 if (copy_from_user(&mv
, (void*)arg
, sizeof (mv
)))
705 if (0 != ch_checkrange(ch
, mv
.cm_fromtype
, mv
.cm_fromunit
) ||
706 0 != ch_checkrange(ch
, mv
.cm_totype
, mv
.cm_tounit
)) {
707 dprintk("CHIOMOVE: invalid parameter\n");
712 retval
= ch_move(ch
,0,
713 ch
->firsts
[mv
.cm_fromtype
] + mv
.cm_fromunit
,
714 ch
->firsts
[mv
.cm_totype
] + mv
.cm_tounit
,
715 mv
.cm_flags
& CM_INVERT
);
722 struct changer_exchange mv
;
724 if (copy_from_user(&mv
, (void*)arg
, sizeof (mv
)))
727 if (0 != ch_checkrange(ch
, mv
.ce_srctype
, mv
.ce_srcunit
) ||
728 0 != ch_checkrange(ch
, mv
.ce_fdsttype
, mv
.ce_fdstunit
) ||
729 0 != ch_checkrange(ch
, mv
.ce_sdsttype
, mv
.ce_sdstunit
)) {
730 dprintk("CHIOEXCHANGE: invalid parameter\n");
737 ch
->firsts
[mv
.ce_srctype
] + mv
.ce_srcunit
,
738 ch
->firsts
[mv
.ce_fdsttype
] + mv
.ce_fdstunit
,
739 ch
->firsts
[mv
.ce_sdsttype
] + mv
.ce_sdstunit
,
740 mv
.ce_flags
& CE_INVERT1
, mv
.ce_flags
& CE_INVERT2
);
747 struct changer_element_status ces
;
749 if (copy_from_user(&ces
, (void*)arg
, sizeof (ces
)))
751 if (ces
.ces_type
< 0 || ces
.ces_type
>= CH_TYPES
)
754 return ch_gstatus(ch
, ces
.ces_type
, ces
.ces_data
);
759 struct changer_get_element cge
;
765 if (copy_from_user(&cge
, (void*)arg
, sizeof (cge
)))
768 if (0 != ch_checkrange(ch
, cge
.cge_type
, cge
.cge_unit
))
770 elem
= ch
->firsts
[cge
.cge_type
] + cge
.cge_unit
;
772 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
778 memset(cmd
,0,sizeof(cmd
));
779 cmd
[0] = READ_ELEMENT_STATUS
;
780 cmd
[1] = (ch
->device
->lun
<< 5) |
781 (ch
->voltags
? 0x10 : 0) |
782 ch_elem_to_typecode(ch
,elem
);
783 cmd
[2] = (elem
>> 8) & 0xff;
784 cmd
[3] = elem
& 0xff;
788 if (0 == (result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_FROM_DEVICE
))) {
789 cge
.cge_status
= buffer
[18];
791 if (buffer
[18] & CESTATUS_EXCEPT
) {
794 if (buffer
[25] & 0x80) {
795 cge
.cge_flags
|= CGE_SRC
;
796 if (buffer
[25] & 0x40)
797 cge
.cge_flags
|= CGE_INVERT
;
798 elem
= (buffer
[26]<<8) | buffer
[27];
799 for (i
= 0; i
< 4; i
++) {
800 if (elem
>= ch
->firsts
[i
] &&
801 elem
< ch
->firsts
[i
] + ch
->counts
[i
]) {
803 cge
.cge_srcunit
= elem
-ch
->firsts
[i
];
807 if ((buffer
[22] & 0x30) == 0x30) {
808 cge
.cge_flags
|= CGE_IDLUN
;
809 cge
.cge_id
= buffer
[23];
810 cge
.cge_lun
= buffer
[22] & 7;
812 if (buffer
[9] & 0x80) {
813 cge
.cge_flags
|= CGE_PVOLTAG
;
814 memcpy(cge
.cge_pvoltag
,buffer
+28,36);
816 if (buffer
[9] & 0x40) {
817 cge
.cge_flags
|= CGE_AVOLTAG
;
818 memcpy(cge
.cge_avoltag
,buffer
+64,36);
820 } else if (ch
->voltags
) {
822 vprintk("device has no volume tag support\n");
828 if (copy_to_user((void*)arg
, &cge
, sizeof (cge
)))
836 retval
= ch_init_elem(ch
);
843 struct changer_set_voltag csv
;
846 if (copy_from_user(&csv
, (void*)arg
, sizeof(csv
)))
849 if (0 != ch_checkrange(ch
, csv
.csv_type
, csv
.csv_unit
)) {
850 dprintk("CHIOSVOLTAG: invalid parameter\n");
853 elem
= ch
->firsts
[csv
.csv_type
] + csv
.csv_unit
;
855 retval
= ch_set_voltag(ch
, elem
,
856 csv
.csv_flags
& CSV_AVOLTAG
,
857 csv
.csv_flags
& CSV_CLEARTAG
,
864 return scsi_ioctl(ch
->device
, cmd
, (void*)arg
);
871 struct changer_element_status32
{
873 compat_uptr_t ces_data
;
875 #define CHIOGSTATUS32 _IOW('c', 8,struct changer_element_status32)
877 static long ch_ioctl_compat(struct file
* file
,
878 unsigned int cmd
, unsigned long arg
)
880 scsi_changer
*ch
= file
->private_data
;
892 return ch_ioctl(NULL
/* inode, unused */,
896 struct changer_element_status32 ces32
;
899 if (copy_from_user(&ces32
, (void*)arg
, sizeof (ces32
)))
901 if (ces32
.ces_type
< 0 || ces32
.ces_type
>= CH_TYPES
)
904 data
= compat_ptr(ces32
.ces_data
);
905 return ch_gstatus(ch
, ces32
.ces_type
, data
);
908 // return scsi_ioctl_compat(ch->device, cmd, (void*)arg);
915 /* ------------------------------------------------------------------------ */
917 static int ch_probe(struct device
*dev
)
919 struct scsi_device
*sd
= to_scsi_device(dev
);
922 if (sd
->type
!= TYPE_MEDIUM_CHANGER
)
925 ch
= kmalloc(sizeof(*ch
), GFP_KERNEL
);
929 memset(ch
,0,sizeof(*ch
));
930 ch
->minor
= ch_devcount
;
931 sprintf(ch
->name
,"ch%d",ch
->minor
);
932 init_MUTEX(&ch
->lock
);
938 class_device_create(ch_sysfs_class
,
939 MKDEV(SCSI_CHANGER_MAJOR
,ch
->minor
),
940 dev
, "s%s", ch
->name
);
942 printk(KERN_INFO
"Attached scsi changer %s "
943 "at scsi%d, channel %d, id %d, lun %d\n",
944 ch
->name
, sd
->host
->host_no
, sd
->channel
, sd
->id
, sd
->lun
);
946 spin_lock(&ch_devlist_lock
);
947 list_add_tail(&ch
->list
,&ch_devlist
);
949 spin_unlock(&ch_devlist_lock
);
953 static int ch_remove(struct device
*dev
)
955 struct scsi_device
*sd
= to_scsi_device(dev
);
956 scsi_changer
*tmp
, *ch
;
958 spin_lock(&ch_devlist_lock
);
960 list_for_each_entry(tmp
,&ch_devlist
,list
) {
961 if (tmp
->device
== sd
)
966 spin_unlock(&ch_devlist_lock
);
968 class_device_destroy(ch_sysfs_class
,
969 MKDEV(SCSI_CHANGER_MAJOR
,ch
->minor
));
976 static int __init
init_ch_module(void)
980 printk(KERN_INFO
"SCSI Media Changer driver v" VERSION
" \n");
981 ch_sysfs_class
= class_create(THIS_MODULE
, "scsi_changer");
982 if (IS_ERR(ch_sysfs_class
)) {
983 rc
= PTR_ERR(ch_sysfs_class
);
986 rc
= register_chrdev(SCSI_CHANGER_MAJOR
,"ch",&changer_fops
);
988 printk("Unable to get major %d for SCSI-Changer\n",
992 rc
= scsi_register_driver(&ch_template
.gendrv
);
998 unregister_chrdev(SCSI_CHANGER_MAJOR
, "ch");
1000 class_destroy(ch_sysfs_class
);
1004 static void __exit
exit_ch_module(void)
1006 scsi_unregister_driver(&ch_template
.gendrv
);
1007 unregister_chrdev(SCSI_CHANGER_MAJOR
, "ch");
1008 class_destroy(ch_sysfs_class
);
1011 module_init(init_ch_module
);
1012 module_exit(exit_ch_module
);