blob: 7aad15436d24d25002cfacee35837401db5e5bee [file] [log] [blame]
Gerd Knorr daa6eda2005-05-10 10:59:13 +02001/*
2 * SCSI Media Changer device driver for Linux 2.6
3 *
4 * (c) 1996-2003 Gerd Knorr <kraxel@bytesex.org>
5 *
6 */
7
8#define VERSION "0.25"
9
Gerd Knorr daa6eda2005-05-10 10:59:13 +020010#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/fs.h>
13#include <linux/kernel.h>
Gerd Knorr daa6eda2005-05-10 10:59:13 +020014#include <linux/mm.h>
15#include <linux/major.h>
16#include <linux/string.h>
17#include <linux/errno.h>
18#include <linux/interrupt.h>
19#include <linux/blkdev.h>
20#include <linux/completion.h>
Gerd Knorr daa6eda2005-05-10 10:59:13 +020021#include <linux/compat.h>
22#include <linux/chio.h> /* here are all the ioctls */
Arjan van de Ven0b950672006-01-11 13:16:10 +010023#include <linux/mutex.h>
FUJITA Tomonorida707c52008-01-24 17:24:50 +090024#include <linux/idr.h>
Gerd Knorr daa6eda2005-05-10 10:59:13 +020025
26#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h>
28#include <scsi/scsi_driver.h>
29#include <scsi/scsi_ioctl.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_device.h>
James Bottomley84743bb2005-06-12 22:37:10 -050032#include <scsi/scsi_eh.h>
Gerd Knorr daa6eda2005-05-10 10:59:13 +020033#include <scsi/scsi_dbg.h>
34
35#define CH_DT_MAX 16
36#define CH_TYPES 8
FUJITA Tomonorida707c52008-01-24 17:24:50 +090037#define CH_MAX_DEVS 128
Gerd Knorr daa6eda2005-05-10 10:59:13 +020038
39MODULE_DESCRIPTION("device driver for scsi media changer devices");
40MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org>");
41MODULE_LICENSE("GPL");
Rene Hermanf018fa52006-03-08 00:14:20 -080042MODULE_ALIAS_CHARDEV_MAJOR(SCSI_CHANGER_MAJOR);
Gerd Knorr daa6eda2005-05-10 10:59:13 +020043
44static int init = 1;
45module_param(init, int, 0444);
46MODULE_PARM_DESC(init, \
47 "initialize element status on driver load (default: on)");
48
49static int timeout_move = 300;
50module_param(timeout_move, int, 0644);
51MODULE_PARM_DESC(timeout_move,"timeout for move commands "
52 "(default: 300 seconds)");
53
54static int timeout_init = 3600;
55module_param(timeout_init, int, 0644);
56MODULE_PARM_DESC(timeout_init,"timeout for INITIALIZE ELEMENT STATUS "
57 "(default: 3600 seconds)");
58
59static int verbose = 1;
60module_param(verbose, int, 0644);
61MODULE_PARM_DESC(verbose,"be verbose (default: on)");
62
63static int debug = 0;
64module_param(debug, int, 0644);
65MODULE_PARM_DESC(debug,"enable/disable debug messages, also prints more "
66 "detailed sense codes on scsi errors (default: off)");
67
68static int dt_id[CH_DT_MAX] = { [ 0 ... (CH_DT_MAX-1) ] = -1 };
69static int dt_lun[CH_DT_MAX];
70module_param_array(dt_id, int, NULL, 0444);
71module_param_array(dt_lun, int, NULL, 0444);
72
73/* tell the driver about vendor-specific slots */
74static int vendor_firsts[CH_TYPES-4];
75static int vendor_counts[CH_TYPES-4];
76module_param_array(vendor_firsts, int, NULL, 0444);
77module_param_array(vendor_counts, int, NULL, 0444);
78
Arjan van de Ven0ad78202005-11-28 16:22:25 +010079static const char * vendor_labels[CH_TYPES-4] = {
Gerd Knorr daa6eda2005-05-10 10:59:13 +020080 "v0", "v1", "v2", "v3"
81};
82// module_param_string_array(vendor_labels, NULL, 0444);
83
84#define dprintk(fmt, arg...) if (debug) \
85 printk(KERN_DEBUG "%s: " fmt, ch->name , ## arg)
86#define vprintk(fmt, arg...) if (verbose) \
87 printk(KERN_INFO "%s: " fmt, ch->name , ## arg)
88
89/* ------------------------------------------------------------------- */
90
91#define MAX_RETRIES 1
92
Gerd Knorr 21feb5c2005-05-12 10:25:26 +020093static struct class * ch_sysfs_class;
Gerd Knorr daa6eda2005-05-10 10:59:13 +020094
95typedef struct {
96 struct list_head list;
97 int minor;
98 char name[8];
99 struct scsi_device *device;
100 struct scsi_device **dt; /* ptrs to data transfer elements */
101 u_int firsts[CH_TYPES];
102 u_int counts[CH_TYPES];
103 u_int unit_attention;
104 u_int voltags;
Arjan van de Ven0b950672006-01-11 13:16:10 +0100105 struct mutex lock;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200106} scsi_changer;
107
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900108static DEFINE_IDR(ch_index_idr);
109static DEFINE_SPINLOCK(ch_index_lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200110
Arjan van de Ven0ad78202005-11-28 16:22:25 +0100111static const struct {
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200112 unsigned char sense;
113 unsigned char asc;
114 unsigned char ascq;
115 int errno;
116} err[] = {
117/* Just filled in what looks right. Hav'nt checked any standard paper for
118 these errno assignments, so they may be wrong... */
119 {
120 .sense = ILLEGAL_REQUEST,
121 .asc = 0x21,
122 .ascq = 0x01,
123 .errno = EBADSLT, /* Invalid element address */
124 },{
125 .sense = ILLEGAL_REQUEST,
126 .asc = 0x28,
127 .ascq = 0x01,
128 .errno = EBADE, /* Import or export element accessed */
129 },{
130 .sense = ILLEGAL_REQUEST,
131 .asc = 0x3B,
132 .ascq = 0x0D,
133 .errno = EXFULL, /* Medium destination element full */
134 },{
135 .sense = ILLEGAL_REQUEST,
136 .asc = 0x3B,
137 .ascq = 0x0E,
138 .errno = EBADE, /* Medium source element empty */
139 },{
140 .sense = ILLEGAL_REQUEST,
141 .asc = 0x20,
142 .ascq = 0x00,
143 .errno = EBADRQC, /* Invalid command operation code */
144 },{
145 /* end of list */
146 }
147};
148
149/* ------------------------------------------------------------------- */
150
James Bottomley84743bb2005-06-12 22:37:10 -0500151static int ch_find_errno(struct scsi_sense_hdr *sshdr)
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200152{
153 int i,errno = 0;
154
155 /* Check to see if additional sense information is available */
James Bottomley84743bb2005-06-12 22:37:10 -0500156 if (scsi_sense_valid(sshdr) &&
157 sshdr->asc != 0) {
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200158 for (i = 0; err[i].errno != 0; i++) {
James Bottomley84743bb2005-06-12 22:37:10 -0500159 if (err[i].sense == sshdr->sense_key &&
160 err[i].asc == sshdr->asc &&
161 err[i].ascq == sshdr->ascq) {
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200162 errno = -err[i].errno;
163 break;
164 }
165 }
166 }
167 if (errno == 0)
168 errno = -EIO;
169 return errno;
170}
171
172static int
173ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
174 void *buffer, unsigned buflength,
175 enum dma_data_direction direction)
176{
James Bottomley84743bb2005-06-12 22:37:10 -0500177 int errno, retries = 0, timeout, result;
178 struct scsi_sense_hdr sshdr;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900179
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200180 timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
181 ? timeout_init : timeout_move;
182
183 retry:
184 errno = 0;
185 if (debug) {
186 dprintk("command: ");
187 __scsi_print_command(cmd);
188 }
189
James Bottomley84743bb2005-06-12 22:37:10 -0500190 result = scsi_execute_req(ch->device, cmd, direction, buffer,
191 buflength, &sshdr, timeout * HZ,
192 MAX_RETRIES);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200193
James Bottomley84743bb2005-06-12 22:37:10 -0500194 dprintk("result: 0x%x\n",result);
195 if (driver_byte(result) & DRIVER_SENSE) {
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200196 if (debug)
James Bottomley84743bb2005-06-12 22:37:10 -0500197 scsi_print_sense_hdr(ch->name, &sshdr);
198 errno = ch_find_errno(&sshdr);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200199
James Bottomley84743bb2005-06-12 22:37:10 -0500200 switch(sshdr.sense_key) {
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200201 case UNIT_ATTENTION:
202 ch->unit_attention = 1;
203 if (retries++ < 3)
204 goto retry;
205 break;
206 }
207 }
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200208 return errno;
209}
210
211/* ------------------------------------------------------------------------ */
212
213static int
214ch_elem_to_typecode(scsi_changer *ch, u_int elem)
215{
216 int i;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900217
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200218 for (i = 0; i < CH_TYPES; i++) {
219 if (elem >= ch->firsts[i] &&
220 elem < ch->firsts[i] +
221 ch->counts[i])
222 return i+1;
223 }
224 return 0;
225}
226
227static int
228ch_read_element_status(scsi_changer *ch, u_int elem, char *data)
229{
230 u_char cmd[12];
231 u_char *buffer;
232 int result;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900233
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200234 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
235 if(!buffer)
236 return -ENOMEM;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900237
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200238 retry:
239 memset(cmd,0,sizeof(cmd));
240 cmd[0] = READ_ELEMENT_STATUS;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900241 cmd[1] = (ch->device->lun << 5) |
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200242 (ch->voltags ? 0x10 : 0) |
243 ch_elem_to_typecode(ch,elem);
244 cmd[2] = (elem >> 8) & 0xff;
245 cmd[3] = elem & 0xff;
246 cmd[5] = 1;
247 cmd[9] = 255;
248 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) {
249 if (((buffer[16] << 8) | buffer[17]) != elem) {
250 dprintk("asked for element 0x%02x, got 0x%02x\n",
251 elem,(buffer[16] << 8) | buffer[17]);
252 kfree(buffer);
253 return -EIO;
254 }
255 memcpy(data,buffer+16,16);
256 } else {
257 if (ch->voltags) {
258 ch->voltags = 0;
259 vprintk("device has no volume tag support\n");
260 goto retry;
261 }
262 dprintk("READ ELEMENT STATUS for element 0x%x failed\n",elem);
263 }
264 kfree(buffer);
265 return result;
266}
267
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900268static int
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200269ch_init_elem(scsi_changer *ch)
270{
271 int err;
272 u_char cmd[6];
273
274 vprintk("INITIALIZE ELEMENT STATUS, may take some time ...\n");
275 memset(cmd,0,sizeof(cmd));
276 cmd[0] = INITIALIZE_ELEMENT_STATUS;
277 cmd[1] = ch->device->lun << 5;
278 err = ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE);
279 vprintk("... finished\n");
280 return err;
281}
282
283static int
284ch_readconfig(scsi_changer *ch)
285{
286 u_char cmd[10], data[16];
287 u_char *buffer;
288 int result,id,lun,i;
289 u_int elem;
290
vignesh.babu@wipro.com4530a162007-04-16 11:35:33 +0530291 buffer = kzalloc(512, GFP_KERNEL | GFP_DMA);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200292 if (!buffer)
293 return -ENOMEM;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900294
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200295 memset(cmd,0,sizeof(cmd));
296 cmd[0] = MODE_SENSE;
297 cmd[1] = ch->device->lun << 5;
298 cmd[2] = 0x1d;
299 cmd[4] = 255;
300 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE);
301 if (0 != result) {
302 cmd[1] |= (1<<3);
303 result = ch_do_scsi(ch, cmd, buffer, 255, DMA_FROM_DEVICE);
304 }
305 if (0 == result) {
306 ch->firsts[CHET_MT] =
307 (buffer[buffer[3]+ 6] << 8) | buffer[buffer[3]+ 7];
308 ch->counts[CHET_MT] =
309 (buffer[buffer[3]+ 8] << 8) | buffer[buffer[3]+ 9];
310 ch->firsts[CHET_ST] =
311 (buffer[buffer[3]+10] << 8) | buffer[buffer[3]+11];
312 ch->counts[CHET_ST] =
313 (buffer[buffer[3]+12] << 8) | buffer[buffer[3]+13];
314 ch->firsts[CHET_IE] =
315 (buffer[buffer[3]+14] << 8) | buffer[buffer[3]+15];
316 ch->counts[CHET_IE] =
317 (buffer[buffer[3]+16] << 8) | buffer[buffer[3]+17];
318 ch->firsts[CHET_DT] =
319 (buffer[buffer[3]+18] << 8) | buffer[buffer[3]+19];
320 ch->counts[CHET_DT] =
321 (buffer[buffer[3]+20] << 8) | buffer[buffer[3]+21];
322 vprintk("type #1 (mt): 0x%x+%d [medium transport]\n",
323 ch->firsts[CHET_MT],
324 ch->counts[CHET_MT]);
325 vprintk("type #2 (st): 0x%x+%d [storage]\n",
326 ch->firsts[CHET_ST],
327 ch->counts[CHET_ST]);
328 vprintk("type #3 (ie): 0x%x+%d [import/export]\n",
329 ch->firsts[CHET_IE],
330 ch->counts[CHET_IE]);
331 vprintk("type #4 (dt): 0x%x+%d [data transfer]\n",
332 ch->firsts[CHET_DT],
333 ch->counts[CHET_DT]);
334 } else {
335 vprintk("reading element address assigment page failed!\n");
336 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900337
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200338 /* vendor specific element types */
339 for (i = 0; i < 4; i++) {
340 if (0 == vendor_counts[i])
341 continue;
342 if (NULL == vendor_labels[i])
343 continue;
344 ch->firsts[CHET_V1+i] = vendor_firsts[i];
345 ch->counts[CHET_V1+i] = vendor_counts[i];
346 vprintk("type #%d (v%d): 0x%x+%d [%s, vendor specific]\n",
347 i+5,i+1,vendor_firsts[i],vendor_counts[i],
348 vendor_labels[i]);
349 }
350
351 /* look up the devices of the data transfer elements */
352 ch->dt = kmalloc(ch->counts[CHET_DT]*sizeof(struct scsi_device),
353 GFP_KERNEL);
354 for (elem = 0; elem < ch->counts[CHET_DT]; elem++) {
355 id = -1;
356 lun = 0;
357 if (elem < CH_DT_MAX && -1 != dt_id[elem]) {
358 id = dt_id[elem];
359 lun = dt_lun[elem];
360 vprintk("dt 0x%x: [insmod option] ",
361 elem+ch->firsts[CHET_DT]);
362 } else if (0 != ch_read_element_status
363 (ch,elem+ch->firsts[CHET_DT],data)) {
364 vprintk("dt 0x%x: READ ELEMENT STATUS failed\n",
365 elem+ch->firsts[CHET_DT]);
366 } else {
367 vprintk("dt 0x%x: ",elem+ch->firsts[CHET_DT]);
368 if (data[6] & 0x80) {
369 if (verbose)
370 printk("not this SCSI bus\n");
371 ch->dt[elem] = NULL;
372 } else if (0 == (data[6] & 0x30)) {
373 if (verbose)
374 printk("ID/LUN unknown\n");
375 ch->dt[elem] = NULL;
376 } else {
377 id = ch->device->id;
378 lun = 0;
379 if (data[6] & 0x20) id = data[7];
380 if (data[6] & 0x10) lun = data[6] & 7;
381 }
382 }
383 if (-1 != id) {
384 if (verbose)
385 printk("ID %i, LUN %i, ",id,lun);
386 ch->dt[elem] =
387 scsi_device_lookup(ch->device->host,
388 ch->device->channel,
389 id,lun);
390 if (!ch->dt[elem]) {
391 /* should not happen */
392 if (verbose)
393 printk("Huh? device not found!\n");
394 } else {
395 if (verbose)
396 printk("name: %8.8s %16.16s %4.4s\n",
397 ch->dt[elem]->vendor,
398 ch->dt[elem]->model,
399 ch->dt[elem]->rev);
400 }
401 }
402 }
403 ch->voltags = 1;
404 kfree(buffer);
405
406 return 0;
407}
408
409/* ------------------------------------------------------------------------ */
410
411static int
412ch_position(scsi_changer *ch, u_int trans, u_int elem, int rotate)
413{
414 u_char cmd[10];
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900415
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200416 dprintk("position: 0x%x\n",elem);
417 if (0 == trans)
418 trans = ch->firsts[CHET_MT];
419 memset(cmd,0,sizeof(cmd));
420 cmd[0] = POSITION_TO_ELEMENT;
421 cmd[1] = ch->device->lun << 5;
422 cmd[2] = (trans >> 8) & 0xff;
423 cmd[3] = trans & 0xff;
424 cmd[4] = (elem >> 8) & 0xff;
425 cmd[5] = elem & 0xff;
426 cmd[8] = rotate ? 1 : 0;
427 return ch_do_scsi(ch, cmd, NULL, 0, DMA_NONE);
428}
429
430static int
431ch_move(scsi_changer *ch, u_int trans, u_int src, u_int dest, int rotate)
432{
433 u_char cmd[12];
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900434
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200435 dprintk("move: 0x%x => 0x%x\n",src,dest);
436 if (0 == trans)
437 trans = ch->firsts[CHET_MT];
438 memset(cmd,0,sizeof(cmd));
439 cmd[0] = MOVE_MEDIUM;
440 cmd[1] = ch->device->lun << 5;
441 cmd[2] = (trans >> 8) & 0xff;
442 cmd[3] = trans & 0xff;
443 cmd[4] = (src >> 8) & 0xff;
444 cmd[5] = src & 0xff;
445 cmd[6] = (dest >> 8) & 0xff;
446 cmd[7] = dest & 0xff;
447 cmd[10] = rotate ? 1 : 0;
448 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE);
449}
450
451static int
452ch_exchange(scsi_changer *ch, u_int trans, u_int src,
453 u_int dest1, u_int dest2, int rotate1, int rotate2)
454{
455 u_char cmd[12];
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900456
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200457 dprintk("exchange: 0x%x => 0x%x => 0x%x\n",
458 src,dest1,dest2);
459 if (0 == trans)
460 trans = ch->firsts[CHET_MT];
461 memset(cmd,0,sizeof(cmd));
462 cmd[0] = EXCHANGE_MEDIUM;
463 cmd[1] = ch->device->lun << 5;
464 cmd[2] = (trans >> 8) & 0xff;
465 cmd[3] = trans & 0xff;
466 cmd[4] = (src >> 8) & 0xff;
467 cmd[5] = src & 0xff;
468 cmd[6] = (dest1 >> 8) & 0xff;
469 cmd[7] = dest1 & 0xff;
470 cmd[8] = (dest2 >> 8) & 0xff;
471 cmd[9] = dest2 & 0xff;
472 cmd[10] = (rotate1 ? 1 : 0) | (rotate2 ? 2 : 0);
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900473
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200474 return ch_do_scsi(ch, cmd, NULL,0, DMA_NONE);
475}
476
477static void
478ch_check_voltag(char *tag)
479{
480 int i;
481
482 for (i = 0; i < 32; i++) {
483 /* restrict to ascii */
484 if (tag[i] >= 0x7f || tag[i] < 0x20)
485 tag[i] = ' ';
486 /* don't allow search wildcards */
487 if (tag[i] == '?' ||
488 tag[i] == '*')
489 tag[i] = ' ';
490 }
491}
492
493static int
494ch_set_voltag(scsi_changer *ch, u_int elem,
495 int alternate, int clear, u_char *tag)
496{
497 u_char cmd[12];
498 u_char *buffer;
499 int result;
500
vignesh.babu@wipro.com4530a162007-04-16 11:35:33 +0530501 buffer = kzalloc(512, GFP_KERNEL);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200502 if (!buffer)
503 return -ENOMEM;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200504
505 dprintk("%s %s voltag: 0x%x => \"%s\"\n",
506 clear ? "clear" : "set",
507 alternate ? "alternate" : "primary",
508 elem, tag);
509 memset(cmd,0,sizeof(cmd));
510 cmd[0] = SEND_VOLUME_TAG;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900511 cmd[1] = (ch->device->lun << 5) |
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200512 ch_elem_to_typecode(ch,elem);
513 cmd[2] = (elem >> 8) & 0xff;
514 cmd[3] = elem & 0xff;
515 cmd[5] = clear
516 ? (alternate ? 0x0d : 0x0c)
517 : (alternate ? 0x0b : 0x0a);
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900518
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200519 cmd[9] = 255;
520
521 memcpy(buffer,tag,32);
522 ch_check_voltag(buffer);
523
524 result = ch_do_scsi(ch, cmd, buffer, 256, DMA_TO_DEVICE);
525 kfree(buffer);
526 return result;
527}
528
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100529static int ch_gstatus(scsi_changer *ch, int type, unsigned char __user *dest)
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200530{
531 int retval = 0;
532 u_char data[16];
533 unsigned int i;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900534
Arjan van de Ven0b950672006-01-11 13:16:10 +0100535 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200536 for (i = 0; i < ch->counts[type]; i++) {
537 if (0 != ch_read_element_status
538 (ch, ch->firsts[type]+i,data)) {
539 retval = -EIO;
540 break;
541 }
542 put_user(data[2], dest+i);
543 if (data[2] & CESTATUS_EXCEPT)
544 vprintk("element 0x%x: asc=0x%x, ascq=0x%x\n",
545 ch->firsts[type]+i,
546 (int)data[4],(int)data[5]);
547 retval = ch_read_element_status
548 (ch, ch->firsts[type]+i,data);
549 if (0 != retval)
550 break;
551 }
Arjan van de Ven0b950672006-01-11 13:16:10 +0100552 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200553 return retval;
554}
555
556/* ------------------------------------------------------------------------ */
557
558static int
559ch_release(struct inode *inode, struct file *file)
560{
561 scsi_changer *ch = file->private_data;
562
563 scsi_device_put(ch->device);
564 file->private_data = NULL;
565 return 0;
566}
567
568static int
569ch_open(struct inode *inode, struct file *file)
570{
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900571 scsi_changer *ch;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200572 int minor = iminor(inode);
573
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900574 spin_lock(&ch_index_lock);
575 ch = idr_find(&ch_index_idr, minor);
576
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200577 if (NULL == ch || scsi_device_get(ch->device)) {
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900578 spin_unlock(&ch_index_lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200579 return -ENXIO;
580 }
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900581 spin_unlock(&ch_index_lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200582
583 file->private_data = ch;
584 return 0;
585}
586
587static int
588ch_checkrange(scsi_changer *ch, unsigned int type, unsigned int unit)
589{
590 if (type >= CH_TYPES || unit >= ch->counts[type])
591 return -1;
592 return 0;
593}
594
Mathieu Segaudf7fea182008-01-14 15:43:18 +0100595static long ch_ioctl(struct file *file,
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200596 unsigned int cmd, unsigned long arg)
597{
598 scsi_changer *ch = file->private_data;
599 int retval;
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100600 void __user *argp = (void __user *)arg;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900601
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200602 switch (cmd) {
603 case CHIOGPARAMS:
604 {
605 struct changer_params params;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900606
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200607 params.cp_curpicker = 0;
608 params.cp_npickers = ch->counts[CHET_MT];
609 params.cp_nslots = ch->counts[CHET_ST];
610 params.cp_nportals = ch->counts[CHET_IE];
611 params.cp_ndrives = ch->counts[CHET_DT];
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900612
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100613 if (copy_to_user(argp, &params, sizeof(params)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200614 return -EFAULT;
615 return 0;
616 }
617 case CHIOGVPARAMS:
618 {
619 struct changer_vendor_params vparams;
620
621 memset(&vparams,0,sizeof(vparams));
622 if (ch->counts[CHET_V1]) {
623 vparams.cvp_n1 = ch->counts[CHET_V1];
624 strncpy(vparams.cvp_label1,vendor_labels[0],16);
625 }
626 if (ch->counts[CHET_V2]) {
627 vparams.cvp_n2 = ch->counts[CHET_V2];
628 strncpy(vparams.cvp_label2,vendor_labels[1],16);
629 }
630 if (ch->counts[CHET_V3]) {
631 vparams.cvp_n3 = ch->counts[CHET_V3];
632 strncpy(vparams.cvp_label3,vendor_labels[2],16);
633 }
634 if (ch->counts[CHET_V4]) {
635 vparams.cvp_n4 = ch->counts[CHET_V4];
636 strncpy(vparams.cvp_label4,vendor_labels[3],16);
637 }
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100638 if (copy_to_user(argp, &vparams, sizeof(vparams)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200639 return -EFAULT;
640 return 0;
641 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900642
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200643 case CHIOPOSITION:
644 {
645 struct changer_position pos;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900646
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100647 if (copy_from_user(&pos, argp, sizeof (pos)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200648 return -EFAULT;
649
650 if (0 != ch_checkrange(ch, pos.cp_type, pos.cp_unit)) {
651 dprintk("CHIOPOSITION: invalid parameter\n");
652 return -EBADSLT;
653 }
Arjan van de Ven0b950672006-01-11 13:16:10 +0100654 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200655 retval = ch_position(ch,0,
656 ch->firsts[pos.cp_type] + pos.cp_unit,
657 pos.cp_flags & CP_INVERT);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100658 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200659 return retval;
660 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900661
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200662 case CHIOMOVE:
663 {
664 struct changer_move mv;
665
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100666 if (copy_from_user(&mv, argp, sizeof (mv)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200667 return -EFAULT;
668
669 if (0 != ch_checkrange(ch, mv.cm_fromtype, mv.cm_fromunit) ||
670 0 != ch_checkrange(ch, mv.cm_totype, mv.cm_tounit )) {
671 dprintk("CHIOMOVE: invalid parameter\n");
672 return -EBADSLT;
673 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900674
Arjan van de Ven0b950672006-01-11 13:16:10 +0100675 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200676 retval = ch_move(ch,0,
677 ch->firsts[mv.cm_fromtype] + mv.cm_fromunit,
678 ch->firsts[mv.cm_totype] + mv.cm_tounit,
679 mv.cm_flags & CM_INVERT);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100680 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200681 return retval;
682 }
683
684 case CHIOEXCHANGE:
685 {
686 struct changer_exchange mv;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900687
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100688 if (copy_from_user(&mv, argp, sizeof (mv)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200689 return -EFAULT;
690
691 if (0 != ch_checkrange(ch, mv.ce_srctype, mv.ce_srcunit ) ||
692 0 != ch_checkrange(ch, mv.ce_fdsttype, mv.ce_fdstunit) ||
693 0 != ch_checkrange(ch, mv.ce_sdsttype, mv.ce_sdstunit)) {
694 dprintk("CHIOEXCHANGE: invalid parameter\n");
695 return -EBADSLT;
696 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900697
Arjan van de Ven0b950672006-01-11 13:16:10 +0100698 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200699 retval = ch_exchange
700 (ch,0,
701 ch->firsts[mv.ce_srctype] + mv.ce_srcunit,
702 ch->firsts[mv.ce_fdsttype] + mv.ce_fdstunit,
703 ch->firsts[mv.ce_sdsttype] + mv.ce_sdstunit,
704 mv.ce_flags & CE_INVERT1, mv.ce_flags & CE_INVERT2);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100705 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200706 return retval;
707 }
708
709 case CHIOGSTATUS:
710 {
711 struct changer_element_status ces;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900712
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100713 if (copy_from_user(&ces, argp, sizeof (ces)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200714 return -EFAULT;
715 if (ces.ces_type < 0 || ces.ces_type >= CH_TYPES)
716 return -EINVAL;
717
718 return ch_gstatus(ch, ces.ces_type, ces.ces_data);
719 }
720
721 case CHIOGELEM:
722 {
723 struct changer_get_element cge;
724 u_char cmd[12];
725 u_char *buffer;
726 unsigned int elem;
727 int result,i;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900728
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100729 if (copy_from_user(&cge, argp, sizeof (cge)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200730 return -EFAULT;
731
732 if (0 != ch_checkrange(ch, cge.cge_type, cge.cge_unit))
733 return -EINVAL;
734 elem = ch->firsts[cge.cge_type] + cge.cge_unit;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900735
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200736 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA);
737 if (!buffer)
738 return -ENOMEM;
Arjan van de Ven0b950672006-01-11 13:16:10 +0100739 mutex_lock(&ch->lock);
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900740
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200741 voltag_retry:
742 memset(cmd,0,sizeof(cmd));
743 cmd[0] = READ_ELEMENT_STATUS;
744 cmd[1] = (ch->device->lun << 5) |
745 (ch->voltags ? 0x10 : 0) |
746 ch_elem_to_typecode(ch,elem);
747 cmd[2] = (elem >> 8) & 0xff;
748 cmd[3] = elem & 0xff;
749 cmd[5] = 1;
750 cmd[9] = 255;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900751
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200752 if (0 == (result = ch_do_scsi(ch, cmd, buffer, 256, DMA_FROM_DEVICE))) {
753 cge.cge_status = buffer[18];
754 cge.cge_flags = 0;
755 if (buffer[18] & CESTATUS_EXCEPT) {
756 cge.cge_errno = EIO;
757 }
758 if (buffer[25] & 0x80) {
759 cge.cge_flags |= CGE_SRC;
760 if (buffer[25] & 0x40)
761 cge.cge_flags |= CGE_INVERT;
762 elem = (buffer[26]<<8) | buffer[27];
763 for (i = 0; i < 4; i++) {
764 if (elem >= ch->firsts[i] &&
765 elem < ch->firsts[i] + ch->counts[i]) {
766 cge.cge_srctype = i;
767 cge.cge_srcunit = elem-ch->firsts[i];
768 }
769 }
770 }
771 if ((buffer[22] & 0x30) == 0x30) {
772 cge.cge_flags |= CGE_IDLUN;
773 cge.cge_id = buffer[23];
774 cge.cge_lun = buffer[22] & 7;
775 }
776 if (buffer[9] & 0x80) {
777 cge.cge_flags |= CGE_PVOLTAG;
778 memcpy(cge.cge_pvoltag,buffer+28,36);
779 }
780 if (buffer[9] & 0x40) {
781 cge.cge_flags |= CGE_AVOLTAG;
782 memcpy(cge.cge_avoltag,buffer+64,36);
783 }
784 } else if (ch->voltags) {
785 ch->voltags = 0;
786 vprintk("device has no volume tag support\n");
787 goto voltag_retry;
788 }
789 kfree(buffer);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100790 mutex_unlock(&ch->lock);
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900791
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100792 if (copy_to_user(argp, &cge, sizeof (cge)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200793 return -EFAULT;
794 return result;
795 }
796
797 case CHIOINITELEM:
798 {
Arjan van de Ven0b950672006-01-11 13:16:10 +0100799 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200800 retval = ch_init_elem(ch);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100801 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200802 return retval;
803 }
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900804
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200805 case CHIOSVOLTAG:
806 {
807 struct changer_set_voltag csv;
808 int elem;
809
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100810 if (copy_from_user(&csv, argp, sizeof(csv)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200811 return -EFAULT;
812
813 if (0 != ch_checkrange(ch, csv.csv_type, csv.csv_unit)) {
814 dprintk("CHIOSVOLTAG: invalid parameter\n");
815 return -EBADSLT;
816 }
817 elem = ch->firsts[csv.csv_type] + csv.csv_unit;
Arjan van de Ven0b950672006-01-11 13:16:10 +0100818 mutex_lock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200819 retval = ch_set_voltag(ch, elem,
820 csv.csv_flags & CSV_AVOLTAG,
821 csv.csv_flags & CSV_CLEARTAG,
822 csv.csv_voltag);
Arjan van de Ven0b950672006-01-11 13:16:10 +0100823 mutex_unlock(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200824 return retval;
825 }
826
827 default:
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100828 return scsi_ioctl(ch->device, cmd, argp);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200829
830 }
831}
832
833#ifdef CONFIG_COMPAT
834
835struct changer_element_status32 {
836 int ces_type;
837 compat_uptr_t ces_data;
838};
839#define CHIOGSTATUS32 _IOW('c', 8,struct changer_element_status32)
840
841static long ch_ioctl_compat(struct file * file,
842 unsigned int cmd, unsigned long arg)
843{
844 scsi_changer *ch = file->private_data;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900845
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200846 switch (cmd) {
847 case CHIOGPARAMS:
848 case CHIOGVPARAMS:
849 case CHIOPOSITION:
850 case CHIOMOVE:
851 case CHIOEXCHANGE:
852 case CHIOGELEM:
853 case CHIOINITELEM:
854 case CHIOSVOLTAG:
855 /* compatible */
Mathieu Segaudf7fea182008-01-14 15:43:18 +0100856 return ch_ioctl(file, cmd, arg);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200857 case CHIOGSTATUS32:
858 {
859 struct changer_element_status32 ces32;
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100860 unsigned char __user *data;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900861
viro@ZenIV.linux.org.ukfe08ac32005-09-09 22:03:44 +0100862 if (copy_from_user(&ces32, (void __user *)arg, sizeof (ces32)))
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200863 return -EFAULT;
864 if (ces32.ces_type < 0 || ces32.ces_type >= CH_TYPES)
865 return -EINVAL;
866
867 data = compat_ptr(ces32.ces_data);
868 return ch_gstatus(ch, ces32.ces_type, data);
869 }
870 default:
871 // return scsi_ioctl_compat(ch->device, cmd, (void*)arg);
872 return -ENOIOCTLCMD;
873
874 }
875}
876#endif
877
878/* ------------------------------------------------------------------------ */
879
880static int ch_probe(struct device *dev)
881{
882 struct scsi_device *sd = to_scsi_device(dev);
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900883 struct class_device *class_dev;
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900884 int minor, ret = -ENOMEM;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200885 scsi_changer *ch;
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900886
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200887 if (sd->type != TYPE_MEDIUM_CHANGER)
888 return -ENODEV;
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900889
vignesh.babu@wipro.com4530a162007-04-16 11:35:33 +0530890 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200891 if (NULL == ch)
892 return -ENOMEM;
893
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900894 if (!idr_pre_get(&ch_index_idr, GFP_KERNEL))
895 goto free_ch;
896
897 spin_lock(&ch_index_lock);
898 ret = idr_get_new(&ch_index_idr, ch, &minor);
899 spin_unlock(&ch_index_lock);
900
901 if (ret)
902 goto free_ch;
903
904 if (minor > CH_MAX_DEVS) {
905 ret = -ENODEV;
906 goto remove_idr;
907 }
908
909 ch->minor = minor;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200910 sprintf(ch->name,"ch%d",ch->minor);
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900911
912 class_dev = class_device_create(ch_sysfs_class, NULL,
913 MKDEV(SCSI_CHANGER_MAJOR, ch->minor),
914 dev, "s%s", ch->name);
915 if (IS_ERR(class_dev)) {
916 printk(KERN_WARNING "ch%d: class_device_create failed\n",
917 ch->minor);
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900918 ret = PTR_ERR(class_dev);
919 goto remove_idr;
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900920 }
921
Arjan van de Ven0b950672006-01-11 13:16:10 +0100922 mutex_init(&ch->lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200923 ch->device = sd;
924 ch_readconfig(ch);
925 if (init)
926 ch_init_elem(ch);
927
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900928 dev_set_drvdata(dev, ch);
Jeff Garzik017560f2005-10-24 18:04:36 -0400929 sdev_printk(KERN_INFO, sd, "Attached scsi changer %s\n", ch->name);
FUJITA Tomonoria3d2c2e2008-01-23 23:34:35 +0900930
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200931 return 0;
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900932remove_idr:
933 idr_remove(&ch_index_idr, minor);
934free_ch:
935 kfree(ch);
936 return ret;
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200937}
938
939static int ch_remove(struct device *dev)
940{
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900941 scsi_changer *ch = dev_get_drvdata(dev);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200942
FUJITA Tomonorida707c52008-01-24 17:24:50 +0900943 spin_lock(&ch_index_lock);
944 idr_remove(&ch_index_idr, ch->minor);
945 spin_unlock(&ch_index_lock);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200946
Gerd Knorr 21feb5c2005-05-12 10:25:26 +0200947 class_device_destroy(ch_sysfs_class,
948 MKDEV(SCSI_CHANGER_MAJOR,ch->minor));
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200949 kfree(ch->dt);
950 kfree(ch);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200951 return 0;
952}
953
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900954static struct scsi_driver ch_template = {
955 .owner = THIS_MODULE,
956 .gendrv = {
957 .name = "ch",
958 .probe = ch_probe,
959 .remove = ch_remove,
960 },
961};
962
963static const struct file_operations changer_fops = {
964 .owner = THIS_MODULE,
965 .open = ch_open,
966 .release = ch_release,
967 .unlocked_ioctl = ch_ioctl,
968#ifdef CONFIG_COMPAT
969 .compat_ioctl = ch_ioctl_compat,
970#endif
971};
972
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200973static int __init init_ch_module(void)
974{
975 int rc;
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +0900976
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200977 printk(KERN_INFO "SCSI Media Changer driver v" VERSION " \n");
Gerd Knorr 21feb5c2005-05-12 10:25:26 +0200978 ch_sysfs_class = class_create(THIS_MODULE, "scsi_changer");
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200979 if (IS_ERR(ch_sysfs_class)) {
980 rc = PTR_ERR(ch_sysfs_class);
981 return rc;
982 }
983 rc = register_chrdev(SCSI_CHANGER_MAJOR,"ch",&changer_fops);
984 if (rc < 0) {
985 printk("Unable to get major %d for SCSI-Changer\n",
986 SCSI_CHANGER_MAJOR);
987 goto fail1;
988 }
989 rc = scsi_register_driver(&ch_template.gendrv);
990 if (rc < 0)
991 goto fail2;
992 return 0;
993
994 fail2:
995 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
996 fail1:
Gerd Knorr 21feb5c2005-05-12 10:25:26 +0200997 class_destroy(ch_sysfs_class);
Gerd Knorr daa6eda2005-05-10 10:59:13 +0200998 return rc;
999}
1000
FUJITA Tomonori5aa22af2008-01-24 17:24:52 +09001001static void __exit exit_ch_module(void)
Gerd Knorr daa6eda2005-05-10 10:59:13 +02001002{
1003 scsi_unregister_driver(&ch_template.gendrv);
1004 unregister_chrdev(SCSI_CHANGER_MAJOR, "ch");
Gerd Knorr 21feb5c2005-05-12 10:25:26 +02001005 class_destroy(ch_sysfs_class);
FUJITA Tomonorida707c52008-01-24 17:24:50 +09001006 idr_destroy(&ch_index_idr);
Gerd Knorr daa6eda2005-05-10 10:59:13 +02001007}
1008
1009module_init(init_ch_module);
1010module_exit(exit_ch_module);
1011
1012/*
1013 * Local variables:
1014 * c-basic-offset: 8
1015 * End:
1016 */