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_request.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(unsigned char *sense_buffer
)
187 /* Check to see if additional sense information is available */
188 if (sense_buffer
[7] > 5 &&
189 sense_buffer
[12] != 0) {
190 for (i
= 0; err
[i
].errno
!= 0; i
++) {
191 if (err
[i
].sense
== sense_buffer
[ 2] &&
192 err
[i
].asc
== sense_buffer
[12] &&
193 err
[i
].ascq
== sense_buffer
[13]) {
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
;
210 struct scsi_request
*sr
;
212 sr
= scsi_allocate_request(ch
->device
, GFP_KERNEL
);
216 timeout
= (cmd
[0] == INITIALIZE_ELEMENT_STATUS
)
217 ? timeout_init
: timeout_move
;
222 dprintk("command: ");
223 __scsi_print_command(cmd
);
226 scsi_wait_req(sr
, cmd
, buffer
, buflength
,
227 timeout
* HZ
, MAX_RETRIES
);
229 dprintk("result: 0x%x\n",sr
->sr_result
);
230 if (driver_byte(sr
->sr_result
) & DRIVER_SENSE
) {
232 scsi_print_req_sense(ch
->name
, sr
);
233 errno
= ch_find_errno(sr
->sr_sense_buffer
);
235 switch(sr
->sr_sense_buffer
[2] & 0xf) {
237 ch
->unit_attention
= 1;
243 scsi_release_request(sr
);
247 /* ------------------------------------------------------------------------ */
250 ch_elem_to_typecode(scsi_changer
*ch
, u_int elem
)
254 for (i
= 0; i
< CH_TYPES
; i
++) {
255 if (elem
>= ch
->firsts
[i
] &&
256 elem
< ch
->firsts
[i
] +
264 ch_read_element_status(scsi_changer
*ch
, u_int elem
, char *data
)
270 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
275 memset(cmd
,0,sizeof(cmd
));
276 cmd
[0] = READ_ELEMENT_STATUS
;
277 cmd
[1] = (ch
->device
->lun
<< 5) |
278 (ch
->voltags
? 0x10 : 0) |
279 ch_elem_to_typecode(ch
,elem
);
280 cmd
[2] = (elem
>> 8) & 0xff;
281 cmd
[3] = elem
& 0xff;
284 if (0 == (result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_FROM_DEVICE
))) {
285 if (((buffer
[16] << 8) | buffer
[17]) != elem
) {
286 dprintk("asked for element 0x%02x, got 0x%02x\n",
287 elem
,(buffer
[16] << 8) | buffer
[17]);
291 memcpy(data
,buffer
+16,16);
295 vprintk("device has no volume tag support\n");
298 dprintk("READ ELEMENT STATUS for element 0x%x failed\n",elem
);
305 ch_init_elem(scsi_changer
*ch
)
310 vprintk("INITIALIZE ELEMENT STATUS, may take some time ...\n");
311 memset(cmd
,0,sizeof(cmd
));
312 cmd
[0] = INITIALIZE_ELEMENT_STATUS
;
313 cmd
[1] = ch
->device
->lun
<< 5;
314 err
= ch_do_scsi(ch
, cmd
, NULL
, 0, DMA_NONE
);
315 vprintk("... finished\n");
320 ch_readconfig(scsi_changer
*ch
)
322 u_char cmd
[10], data
[16];
327 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
330 memset(buffer
,0,512);
332 memset(cmd
,0,sizeof(cmd
));
334 cmd
[1] = ch
->device
->lun
<< 5;
337 result
= ch_do_scsi(ch
, cmd
, buffer
, 255, DMA_FROM_DEVICE
);
340 result
= ch_do_scsi(ch
, cmd
, buffer
, 255, DMA_FROM_DEVICE
);
343 ch
->firsts
[CHET_MT
] =
344 (buffer
[buffer
[3]+ 6] << 8) | buffer
[buffer
[3]+ 7];
345 ch
->counts
[CHET_MT
] =
346 (buffer
[buffer
[3]+ 8] << 8) | buffer
[buffer
[3]+ 9];
347 ch
->firsts
[CHET_ST
] =
348 (buffer
[buffer
[3]+10] << 8) | buffer
[buffer
[3]+11];
349 ch
->counts
[CHET_ST
] =
350 (buffer
[buffer
[3]+12] << 8) | buffer
[buffer
[3]+13];
351 ch
->firsts
[CHET_IE
] =
352 (buffer
[buffer
[3]+14] << 8) | buffer
[buffer
[3]+15];
353 ch
->counts
[CHET_IE
] =
354 (buffer
[buffer
[3]+16] << 8) | buffer
[buffer
[3]+17];
355 ch
->firsts
[CHET_DT
] =
356 (buffer
[buffer
[3]+18] << 8) | buffer
[buffer
[3]+19];
357 ch
->counts
[CHET_DT
] =
358 (buffer
[buffer
[3]+20] << 8) | buffer
[buffer
[3]+21];
359 vprintk("type #1 (mt): 0x%x+%d [medium transport]\n",
361 ch
->counts
[CHET_MT
]);
362 vprintk("type #2 (st): 0x%x+%d [storage]\n",
364 ch
->counts
[CHET_ST
]);
365 vprintk("type #3 (ie): 0x%x+%d [import/export]\n",
367 ch
->counts
[CHET_IE
]);
368 vprintk("type #4 (dt): 0x%x+%d [data transfer]\n",
370 ch
->counts
[CHET_DT
]);
372 vprintk("reading element address assigment page failed!\n");
375 /* vendor specific element types */
376 for (i
= 0; i
< 4; i
++) {
377 if (0 == vendor_counts
[i
])
379 if (NULL
== vendor_labels
[i
])
381 ch
->firsts
[CHET_V1
+i
] = vendor_firsts
[i
];
382 ch
->counts
[CHET_V1
+i
] = vendor_counts
[i
];
383 vprintk("type #%d (v%d): 0x%x+%d [%s, vendor specific]\n",
384 i
+5,i
+1,vendor_firsts
[i
],vendor_counts
[i
],
388 /* look up the devices of the data transfer elements */
389 ch
->dt
= kmalloc(ch
->counts
[CHET_DT
]*sizeof(struct scsi_device
),
391 for (elem
= 0; elem
< ch
->counts
[CHET_DT
]; elem
++) {
394 if (elem
< CH_DT_MAX
&& -1 != dt_id
[elem
]) {
397 vprintk("dt 0x%x: [insmod option] ",
398 elem
+ch
->firsts
[CHET_DT
]);
399 } else if (0 != ch_read_element_status
400 (ch
,elem
+ch
->firsts
[CHET_DT
],data
)) {
401 vprintk("dt 0x%x: READ ELEMENT STATUS failed\n",
402 elem
+ch
->firsts
[CHET_DT
]);
404 vprintk("dt 0x%x: ",elem
+ch
->firsts
[CHET_DT
]);
405 if (data
[6] & 0x80) {
407 printk("not this SCSI bus\n");
409 } else if (0 == (data
[6] & 0x30)) {
411 printk("ID/LUN unknown\n");
416 if (data
[6] & 0x20) id
= data
[7];
417 if (data
[6] & 0x10) lun
= data
[6] & 7;
422 printk("ID %i, LUN %i, ",id
,lun
);
424 scsi_device_lookup(ch
->device
->host
,
428 /* should not happen */
430 printk("Huh? device not found!\n");
433 printk("name: %8.8s %16.16s %4.4s\n",
434 ch
->dt
[elem
]->vendor
,
446 /* ------------------------------------------------------------------------ */
449 ch_position(scsi_changer
*ch
, u_int trans
, u_int elem
, int rotate
)
453 dprintk("position: 0x%x\n",elem
);
455 trans
= ch
->firsts
[CHET_MT
];
456 memset(cmd
,0,sizeof(cmd
));
457 cmd
[0] = POSITION_TO_ELEMENT
;
458 cmd
[1] = ch
->device
->lun
<< 5;
459 cmd
[2] = (trans
>> 8) & 0xff;
460 cmd
[3] = trans
& 0xff;
461 cmd
[4] = (elem
>> 8) & 0xff;
462 cmd
[5] = elem
& 0xff;
463 cmd
[8] = rotate
? 1 : 0;
464 return ch_do_scsi(ch
, cmd
, NULL
, 0, DMA_NONE
);
468 ch_move(scsi_changer
*ch
, u_int trans
, u_int src
, u_int dest
, int rotate
)
472 dprintk("move: 0x%x => 0x%x\n",src
,dest
);
474 trans
= ch
->firsts
[CHET_MT
];
475 memset(cmd
,0,sizeof(cmd
));
476 cmd
[0] = MOVE_MEDIUM
;
477 cmd
[1] = ch
->device
->lun
<< 5;
478 cmd
[2] = (trans
>> 8) & 0xff;
479 cmd
[3] = trans
& 0xff;
480 cmd
[4] = (src
>> 8) & 0xff;
482 cmd
[6] = (dest
>> 8) & 0xff;
483 cmd
[7] = dest
& 0xff;
484 cmd
[10] = rotate
? 1 : 0;
485 return ch_do_scsi(ch
, cmd
, NULL
,0, DMA_NONE
);
489 ch_exchange(scsi_changer
*ch
, u_int trans
, u_int src
,
490 u_int dest1
, u_int dest2
, int rotate1
, int rotate2
)
494 dprintk("exchange: 0x%x => 0x%x => 0x%x\n",
497 trans
= ch
->firsts
[CHET_MT
];
498 memset(cmd
,0,sizeof(cmd
));
499 cmd
[0] = EXCHANGE_MEDIUM
;
500 cmd
[1] = ch
->device
->lun
<< 5;
501 cmd
[2] = (trans
>> 8) & 0xff;
502 cmd
[3] = trans
& 0xff;
503 cmd
[4] = (src
>> 8) & 0xff;
505 cmd
[6] = (dest1
>> 8) & 0xff;
506 cmd
[7] = dest1
& 0xff;
507 cmd
[8] = (dest2
>> 8) & 0xff;
508 cmd
[9] = dest2
& 0xff;
509 cmd
[10] = (rotate1
? 1 : 0) | (rotate2
? 2 : 0);
511 return ch_do_scsi(ch
, cmd
, NULL
,0, DMA_NONE
);
515 ch_check_voltag(char *tag
)
519 for (i
= 0; i
< 32; i
++) {
520 /* restrict to ascii */
521 if (tag
[i
] >= 0x7f || tag
[i
] < 0x20)
523 /* don't allow search wildcards */
531 ch_set_voltag(scsi_changer
*ch
, u_int elem
,
532 int alternate
, int clear
, u_char
*tag
)
538 buffer
= kmalloc(512, GFP_KERNEL
);
541 memset(buffer
,0,512);
543 dprintk("%s %s voltag: 0x%x => \"%s\"\n",
544 clear
? "clear" : "set",
545 alternate
? "alternate" : "primary",
547 memset(cmd
,0,sizeof(cmd
));
548 cmd
[0] = SEND_VOLUME_TAG
;
549 cmd
[1] = (ch
->device
->lun
<< 5) |
550 ch_elem_to_typecode(ch
,elem
);
551 cmd
[2] = (elem
>> 8) & 0xff;
552 cmd
[3] = elem
& 0xff;
554 ? (alternate
? 0x0d : 0x0c)
555 : (alternate
? 0x0b : 0x0a);
559 memcpy(buffer
,tag
,32);
560 ch_check_voltag(buffer
);
562 result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_TO_DEVICE
);
567 static int ch_gstatus(scsi_changer
*ch
, int type
, unsigned char *dest
)
574 for (i
= 0; i
< ch
->counts
[type
]; i
++) {
575 if (0 != ch_read_element_status
576 (ch
, ch
->firsts
[type
]+i
,data
)) {
580 put_user(data
[2], dest
+i
);
581 if (data
[2] & CESTATUS_EXCEPT
)
582 vprintk("element 0x%x: asc=0x%x, ascq=0x%x\n",
584 (int)data
[4],(int)data
[5]);
585 retval
= ch_read_element_status
586 (ch
, ch
->firsts
[type
]+i
,data
);
594 /* ------------------------------------------------------------------------ */
597 ch_release(struct inode
*inode
, struct file
*file
)
599 scsi_changer
*ch
= file
->private_data
;
601 scsi_device_put(ch
->device
);
602 file
->private_data
= NULL
;
607 ch_open(struct inode
*inode
, struct file
*file
)
609 scsi_changer
*tmp
, *ch
;
610 int minor
= iminor(inode
);
612 spin_lock(&ch_devlist_lock
);
614 list_for_each_entry(tmp
,&ch_devlist
,list
) {
615 if (tmp
->minor
== minor
)
618 if (NULL
== ch
|| scsi_device_get(ch
->device
)) {
619 spin_unlock(&ch_devlist_lock
);
622 spin_unlock(&ch_devlist_lock
);
624 file
->private_data
= ch
;
629 ch_checkrange(scsi_changer
*ch
, unsigned int type
, unsigned int unit
)
631 if (type
>= CH_TYPES
|| unit
>= ch
->counts
[type
])
636 static int ch_ioctl(struct inode
* inode
, struct file
* file
,
637 unsigned int cmd
, unsigned long arg
)
639 scsi_changer
*ch
= file
->private_data
;
645 struct changer_params params
;
647 params
.cp_curpicker
= 0;
648 params
.cp_npickers
= ch
->counts
[CHET_MT
];
649 params
.cp_nslots
= ch
->counts
[CHET_ST
];
650 params
.cp_nportals
= ch
->counts
[CHET_IE
];
651 params
.cp_ndrives
= ch
->counts
[CHET_DT
];
653 if (copy_to_user((void *) arg
, ¶ms
, sizeof(params
)))
659 struct changer_vendor_params vparams
;
661 memset(&vparams
,0,sizeof(vparams
));
662 if (ch
->counts
[CHET_V1
]) {
663 vparams
.cvp_n1
= ch
->counts
[CHET_V1
];
664 strncpy(vparams
.cvp_label1
,vendor_labels
[0],16);
666 if (ch
->counts
[CHET_V2
]) {
667 vparams
.cvp_n2
= ch
->counts
[CHET_V2
];
668 strncpy(vparams
.cvp_label2
,vendor_labels
[1],16);
670 if (ch
->counts
[CHET_V3
]) {
671 vparams
.cvp_n3
= ch
->counts
[CHET_V3
];
672 strncpy(vparams
.cvp_label3
,vendor_labels
[2],16);
674 if (ch
->counts
[CHET_V4
]) {
675 vparams
.cvp_n4
= ch
->counts
[CHET_V4
];
676 strncpy(vparams
.cvp_label4
,vendor_labels
[3],16);
678 if (copy_to_user((void *) arg
, &vparams
, sizeof(vparams
)))
685 struct changer_position pos
;
687 if (copy_from_user(&pos
, (void*)arg
, sizeof (pos
)))
690 if (0 != ch_checkrange(ch
, pos
.cp_type
, pos
.cp_unit
)) {
691 dprintk("CHIOPOSITION: invalid parameter\n");
695 retval
= ch_position(ch
,0,
696 ch
->firsts
[pos
.cp_type
] + pos
.cp_unit
,
697 pos
.cp_flags
& CP_INVERT
);
704 struct changer_move mv
;
706 if (copy_from_user(&mv
, (void*)arg
, sizeof (mv
)))
709 if (0 != ch_checkrange(ch
, mv
.cm_fromtype
, mv
.cm_fromunit
) ||
710 0 != ch_checkrange(ch
, mv
.cm_totype
, mv
.cm_tounit
)) {
711 dprintk("CHIOMOVE: invalid parameter\n");
716 retval
= ch_move(ch
,0,
717 ch
->firsts
[mv
.cm_fromtype
] + mv
.cm_fromunit
,
718 ch
->firsts
[mv
.cm_totype
] + mv
.cm_tounit
,
719 mv
.cm_flags
& CM_INVERT
);
726 struct changer_exchange mv
;
728 if (copy_from_user(&mv
, (void*)arg
, sizeof (mv
)))
731 if (0 != ch_checkrange(ch
, mv
.ce_srctype
, mv
.ce_srcunit
) ||
732 0 != ch_checkrange(ch
, mv
.ce_fdsttype
, mv
.ce_fdstunit
) ||
733 0 != ch_checkrange(ch
, mv
.ce_sdsttype
, mv
.ce_sdstunit
)) {
734 dprintk("CHIOEXCHANGE: invalid parameter\n");
741 ch
->firsts
[mv
.ce_srctype
] + mv
.ce_srcunit
,
742 ch
->firsts
[mv
.ce_fdsttype
] + mv
.ce_fdstunit
,
743 ch
->firsts
[mv
.ce_sdsttype
] + mv
.ce_sdstunit
,
744 mv
.ce_flags
& CE_INVERT1
, mv
.ce_flags
& CE_INVERT2
);
751 struct changer_element_status ces
;
753 if (copy_from_user(&ces
, (void*)arg
, sizeof (ces
)))
755 if (ces
.ces_type
< 0 || ces
.ces_type
>= CH_TYPES
)
758 return ch_gstatus(ch
, ces
.ces_type
, ces
.ces_data
);
763 struct changer_get_element cge
;
769 if (copy_from_user(&cge
, (void*)arg
, sizeof (cge
)))
772 if (0 != ch_checkrange(ch
, cge
.cge_type
, cge
.cge_unit
))
774 elem
= ch
->firsts
[cge
.cge_type
] + cge
.cge_unit
;
776 buffer
= kmalloc(512, GFP_KERNEL
| GFP_DMA
);
782 memset(cmd
,0,sizeof(cmd
));
783 cmd
[0] = READ_ELEMENT_STATUS
;
784 cmd
[1] = (ch
->device
->lun
<< 5) |
785 (ch
->voltags
? 0x10 : 0) |
786 ch_elem_to_typecode(ch
,elem
);
787 cmd
[2] = (elem
>> 8) & 0xff;
788 cmd
[3] = elem
& 0xff;
792 if (0 == (result
= ch_do_scsi(ch
, cmd
, buffer
, 256, DMA_FROM_DEVICE
))) {
793 cge
.cge_status
= buffer
[18];
795 if (buffer
[18] & CESTATUS_EXCEPT
) {
798 if (buffer
[25] & 0x80) {
799 cge
.cge_flags
|= CGE_SRC
;
800 if (buffer
[25] & 0x40)
801 cge
.cge_flags
|= CGE_INVERT
;
802 elem
= (buffer
[26]<<8) | buffer
[27];
803 for (i
= 0; i
< 4; i
++) {
804 if (elem
>= ch
->firsts
[i
] &&
805 elem
< ch
->firsts
[i
] + ch
->counts
[i
]) {
807 cge
.cge_srcunit
= elem
-ch
->firsts
[i
];
811 if ((buffer
[22] & 0x30) == 0x30) {
812 cge
.cge_flags
|= CGE_IDLUN
;
813 cge
.cge_id
= buffer
[23];
814 cge
.cge_lun
= buffer
[22] & 7;
816 if (buffer
[9] & 0x80) {
817 cge
.cge_flags
|= CGE_PVOLTAG
;
818 memcpy(cge
.cge_pvoltag
,buffer
+28,36);
820 if (buffer
[9] & 0x40) {
821 cge
.cge_flags
|= CGE_AVOLTAG
;
822 memcpy(cge
.cge_avoltag
,buffer
+64,36);
824 } else if (ch
->voltags
) {
826 vprintk("device has no volume tag support\n");
832 if (copy_to_user((void*)arg
, &cge
, sizeof (cge
)))
840 retval
= ch_init_elem(ch
);
847 struct changer_set_voltag csv
;
850 if (copy_from_user(&csv
, (void*)arg
, sizeof(csv
)))
853 if (0 != ch_checkrange(ch
, csv
.csv_type
, csv
.csv_unit
)) {
854 dprintk("CHIOSVOLTAG: invalid parameter\n");
857 elem
= ch
->firsts
[csv
.csv_type
] + csv
.csv_unit
;
859 retval
= ch_set_voltag(ch
, elem
,
860 csv
.csv_flags
& CSV_AVOLTAG
,
861 csv
.csv_flags
& CSV_CLEARTAG
,
868 return scsi_ioctl(ch
->device
, cmd
, (void*)arg
);
875 struct changer_element_status32
{
877 compat_uptr_t ces_data
;
879 #define CHIOGSTATUS32 _IOW('c', 8,struct changer_element_status32)
881 static long ch_ioctl_compat(struct file
* file
,
882 unsigned int cmd
, unsigned long arg
)
884 scsi_changer
*ch
= file
->private_data
;
896 return ch_ioctl(NULL
/* inode, unused */,
900 struct changer_element_status32 ces32
;
903 if (copy_from_user(&ces32
, (void*)arg
, sizeof (ces32
)))
905 if (ces32
.ces_type
< 0 || ces32
.ces_type
>= CH_TYPES
)
908 data
= compat_ptr(ces32
.ces_data
);
909 return ch_gstatus(ch
, ces32
.ces_type
, data
);
912 // return scsi_ioctl_compat(ch->device, cmd, (void*)arg);
919 /* ------------------------------------------------------------------------ */
921 static int ch_probe(struct device
*dev
)
923 struct scsi_device
*sd
= to_scsi_device(dev
);
926 if (sd
->type
!= TYPE_MEDIUM_CHANGER
)
929 ch
= kmalloc(sizeof(*ch
), GFP_KERNEL
);
933 memset(ch
,0,sizeof(*ch
));
934 ch
->minor
= ch_devcount
;
935 sprintf(ch
->name
,"ch%d",ch
->minor
);
936 init_MUTEX(&ch
->lock
);
942 class_device_create(ch_sysfs_class
,
943 MKDEV(SCSI_CHANGER_MAJOR
,ch
->minor
),
944 dev
, "s%s", ch
->name
);
946 printk(KERN_INFO
"Attached scsi changer %s "
947 "at scsi%d, channel %d, id %d, lun %d\n",
948 ch
->name
, sd
->host
->host_no
, sd
->channel
, sd
->id
, sd
->lun
);
950 spin_lock(&ch_devlist_lock
);
951 list_add_tail(&ch
->list
,&ch_devlist
);
953 spin_unlock(&ch_devlist_lock
);
957 static int ch_remove(struct device
*dev
)
959 struct scsi_device
*sd
= to_scsi_device(dev
);
960 scsi_changer
*tmp
, *ch
;
962 spin_lock(&ch_devlist_lock
);
964 list_for_each_entry(tmp
,&ch_devlist
,list
) {
965 if (tmp
->device
== sd
)
970 spin_unlock(&ch_devlist_lock
);
972 class_device_destroy(ch_sysfs_class
,
973 MKDEV(SCSI_CHANGER_MAJOR
,ch
->minor
));
980 static int __init
init_ch_module(void)
984 printk(KERN_INFO
"SCSI Media Changer driver v" VERSION
" \n");
985 ch_sysfs_class
= class_create(THIS_MODULE
, "scsi_changer");
986 if (IS_ERR(ch_sysfs_class
)) {
987 rc
= PTR_ERR(ch_sysfs_class
);
990 rc
= register_chrdev(SCSI_CHANGER_MAJOR
,"ch",&changer_fops
);
992 printk("Unable to get major %d for SCSI-Changer\n",
996 rc
= scsi_register_driver(&ch_template
.gendrv
);
1002 unregister_chrdev(SCSI_CHANGER_MAJOR
, "ch");
1004 class_destroy(ch_sysfs_class
);
1008 static void __exit
exit_ch_module(void)
1010 scsi_unregister_driver(&ch_template
.gendrv
);
1011 unregister_chrdev(SCSI_CHANGER_MAJOR
, "ch");
1012 class_destroy(ch_sysfs_class
);
1015 module_init(init_ch_module
);
1016 module_exit(exit_ch_module
);