ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / scsi / ide-scsi.c
1 /*
2  * linux/drivers/scsi/ide-scsi.c        Version 0.9             Jul   4, 1999
3  *
4  * Copyright (C) 1996 - 1999 Gadi Oxman <gadio@netvision.net.il>
5  */
6
7 /*
8  * Emulation of a SCSI host adapter for IDE ATAPI devices.
9  *
10  * With this driver, one can use the Linux SCSI drivers instead of the
11  * native IDE ATAPI drivers.
12  *
13  * Ver 0.1   Dec  3 96   Initial version.
14  * Ver 0.2   Jan 26 97   Fixed bug in cleanup_module() and added emulation
15  *                        of MODE_SENSE_6/MODE_SELECT_6 for cdroms. Thanks
16  *                        to Janos Farkas for pointing this out.
17  *                       Avoid using bitfields in structures for m68k.
18  *                       Added Scatter/Gather and DMA support.
19  * Ver 0.4   Dec  7 97   Add support for ATAPI PD/CD drives.
20  *                       Use variable timeout for each command.
21  * Ver 0.5   Jan  2 98   Fix previous PD/CD support.
22  *                       Allow disabling of SCSI-6 to SCSI-10 transformation.
23  * Ver 0.6   Jan 27 98   Allow disabling of SCSI command translation layer
24  *                        for access through /dev/sg.
25  *                       Fix MODE_SENSE_6/MODE_SELECT_6/INQUIRY translation.
26  * Ver 0.7   Dec 04 98   Ignore commands where lun != 0 to avoid multiple
27  *                        detection of devices with CONFIG_SCSI_MULTI_LUN
28  * Ver 0.8   Feb 05 99   Optical media need translation too. Reverse 0.7.
29  * Ver 0.9   Jul 04 99   Fix a bug in SG_SET_TRANSFORM.
30  * Ver 0.91  Jun 10 02   Fix "off by one" error in transforms
31  * Ver 0.92  Dec 31 02   Implement new SCSI mid level API
32  */
33
34 #define IDESCSI_VERSION "0.92"
35
36 #include <linux/module.h>
37 #include <linux/config.h>
38 #include <linux/types.h>
39 #include <linux/string.h>
40 #include <linux/kernel.h>
41 #include <linux/mm.h>
42 #include <linux/ioport.h>
43 #include <linux/blkdev.h>
44 #include <linux/errno.h>
45 #include <linux/hdreg.h>
46 #include <linux/slab.h>
47 #include <linux/ide.h>
48
49 #include <asm/io.h>
50 #include <asm/bitops.h>
51 #include <asm/uaccess.h>
52
53 #include "scsi.h"
54 #include "hosts.h"
55 #include <scsi/sg.h>
56
57 #define IDESCSI_DEBUG_LOG               0
58
59 typedef struct idescsi_pc_s {
60         u8 c[12];                               /* Actual packet bytes */
61         int request_transfer;                   /* Bytes to transfer */
62         int actually_transferred;               /* Bytes actually transferred */
63         int buffer_size;                        /* Size of our data buffer */
64         struct request *rq;                     /* The corresponding request */
65         u8 *buffer;                             /* Data buffer */
66         u8 *current_position;                   /* Pointer into the above buffer */
67         struct scatterlist *sg;                 /* Scatter gather table */
68         int b_count;                            /* Bytes transferred from current entry */
69         Scsi_Cmnd *scsi_cmd;                    /* SCSI command */
70         void (*done)(Scsi_Cmnd *);              /* Scsi completion routine */
71         unsigned long flags;                    /* Status/Action flags */
72         unsigned long timeout;                  /* Command timeout */
73 } idescsi_pc_t;
74
75 /*
76  *      Packet command status bits.
77  */
78 #define PC_DMA_IN_PROGRESS              0       /* 1 while DMA in progress */
79 #define PC_WRITING                      1       /* Data direction */
80 #define PC_TRANSFORM                    2       /* transform SCSI commands */
81 #define PC_TIMEDOUT                     3       /* command timed out */
82 #define PC_DMA_OK                       4       /* Use DMA */
83
84 /*
85  *      SCSI command transformation layer
86  */
87 #define IDESCSI_TRANSFORM               0       /* Enable/Disable transformation */
88 #define IDESCSI_SG_TRANSFORM            1       /* /dev/sg transformation */
89
90 /*
91  *      Log flags
92  */
93 #define IDESCSI_LOG_CMD                 0       /* Log SCSI commands */
94
95 typedef struct {
96         ide_drive_t *drive;
97         idescsi_pc_t *pc;                       /* Current packet command */
98         unsigned long flags;                    /* Status/Action flags */
99         unsigned long transform;                /* SCSI cmd translation layer */
100         unsigned long log;                      /* log flags */
101 } idescsi_scsi_t;
102
103 static inline idescsi_scsi_t *scsihost_to_idescsi(struct Scsi_Host *host)
104 {
105         return (idescsi_scsi_t*) (&host[1]);
106 }
107
108 static inline idescsi_scsi_t *drive_to_idescsi(ide_drive_t *ide_drive)
109 {
110         return scsihost_to_idescsi(ide_drive->driver_data);
111 }
112
113 /*
114  *      Per ATAPI device status bits.
115  */
116 #define IDESCSI_DRQ_INTERRUPT           0       /* DRQ interrupt device */
117
118 /*
119  *      ide-scsi requests.
120  */
121 #define IDESCSI_PC_RQ                   90
122
123 static void idescsi_discard_data (ide_drive_t *drive, unsigned int bcount)
124 {
125         while (bcount--)
126                 (void) HWIF(drive)->INB(IDE_DATA_REG);
127 }
128
129 static void idescsi_output_zeros (ide_drive_t *drive, unsigned int bcount)
130 {
131         while (bcount--)
132                 HWIF(drive)->OUTB(0, IDE_DATA_REG);
133 }
134
135 /*
136  *      PIO data transfer routines using the scatter gather table.
137  */
138 static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount)
139 {
140         int count;
141         char *buf;
142
143         while (bcount) {
144                 if (pc->sg - (struct scatterlist *) pc->scsi_cmd->request_buffer > pc->scsi_cmd->use_sg) {
145                         printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
146                         idescsi_discard_data (drive, bcount);
147                         return;
148                 }
149                 count = min(pc->sg->length - pc->b_count, bcount);
150                 buf = page_address(pc->sg->page) + pc->sg->offset;
151                 atapi_input_bytes (drive, buf + pc->b_count, count);
152                 bcount -= count; pc->b_count += count;
153                 if (pc->b_count == pc->sg->length) {
154                         pc->sg++;
155                         pc->b_count = 0;
156                 }
157         }
158 }
159
160 static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount)
161 {
162         int count;
163         char *buf;
164
165         while (bcount) {
166                 if (pc->sg - (struct scatterlist *) pc->scsi_cmd->request_buffer > pc->scsi_cmd->use_sg) {
167                         printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
168                         idescsi_output_zeros (drive, bcount);
169                         return;
170                 }
171                 count = min(pc->sg->length - pc->b_count, bcount);
172                 buf = page_address(pc->sg->page) + pc->sg->offset;
173                 atapi_output_bytes (drive, buf + pc->b_count, count);
174                 bcount -= count; pc->b_count += count;
175                 if (pc->b_count == pc->sg->length) {
176                         pc->sg++;
177                         pc->b_count = 0;
178                 }
179         }
180 }
181
182 /*
183  *      Most of the SCSI commands are supported directly by ATAPI devices.
184  *      idescsi_transform_pc handles the few exceptions.
185  */
186 static inline void idescsi_transform_pc1 (ide_drive_t *drive, idescsi_pc_t *pc)
187 {
188         u8 *c = pc->c, *scsi_buf = pc->buffer, *sc = pc->scsi_cmd->cmnd;
189         char *atapi_buf;
190
191         if (!test_bit(PC_TRANSFORM, &pc->flags))
192                 return;
193         if (drive->media == ide_cdrom || drive->media == ide_optical) {
194                 if (c[0] == READ_6 || c[0] == WRITE_6) {
195                         c[8] = c[4];            c[5] = c[3];            c[4] = c[2];
196                         c[3] = c[1] & 0x1f;     c[2] = 0;               c[1] &= 0xe0;
197                         c[0] += (READ_10 - READ_6);
198                 }
199                 if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
200                         unsigned short new_len;
201                         if (!scsi_buf)
202                                 return;
203                         if ((atapi_buf = kmalloc(pc->buffer_size + 4, GFP_ATOMIC)) == NULL)
204                                 return;
205                         memset(atapi_buf, 0, pc->buffer_size + 4);
206                         memset (c, 0, 12);
207                         c[0] = sc[0] | 0x40;
208                         c[1] = sc[1];
209                         c[2] = sc[2];
210                         new_len = sc[4] + 4;
211                         c[8] = new_len;
212                         c[7] = new_len >> 8;
213                         c[9] = sc[5];
214                         if (c[0] == MODE_SELECT_10) {
215                                 atapi_buf[1] = scsi_buf[0];     /* Mode data length */
216                                 atapi_buf[2] = scsi_buf[1];     /* Medium type */
217                                 atapi_buf[3] = scsi_buf[2];     /* Device specific parameter */
218                                 atapi_buf[7] = scsi_buf[3];     /* Block descriptor length */
219                                 memcpy(atapi_buf + 8, scsi_buf + 4, pc->buffer_size - 4);
220                         }
221                         pc->buffer = atapi_buf;
222                         pc->request_transfer += 4;
223                         pc->buffer_size += 4;
224                 }
225         }
226 }
227
228 static inline void idescsi_transform_pc2 (ide_drive_t *drive, idescsi_pc_t *pc)
229 {
230         u8 *atapi_buf = pc->buffer;
231         u8 *sc = pc->scsi_cmd->cmnd;
232         u8 *scsi_buf = pc->scsi_cmd->request_buffer;
233
234         if (!test_bit(PC_TRANSFORM, &pc->flags))
235                 return;
236         if (drive->media == ide_cdrom || drive->media == ide_optical) {
237                 if (pc->c[0] == MODE_SENSE_10 && sc[0] == MODE_SENSE) {
238                         scsi_buf[0] = atapi_buf[1];             /* Mode data length */
239                         scsi_buf[1] = atapi_buf[2];             /* Medium type */
240                         scsi_buf[2] = atapi_buf[3];             /* Device specific parameter */
241                         scsi_buf[3] = atapi_buf[7];             /* Block descriptor length */
242                         memcpy(scsi_buf + 4, atapi_buf + 8, pc->request_transfer - 8);
243                 }
244                 if (pc->c[0] == INQUIRY) {
245                         scsi_buf[2] |= 2;                       /* ansi_revision */
246                         scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2; /* response data format */
247                 }
248         }
249         if (atapi_buf && atapi_buf != scsi_buf)
250                 kfree(atapi_buf);
251 }
252
253 static inline void idescsi_free_bio (struct bio *bio)
254 {
255         struct bio *bhp;
256
257         while (bio) {
258                 bhp = bio;
259                 bio = bio->bi_next;
260                 bio_put(bhp);
261         }
262 }
263
264 static void hexdump(u8 *x, int len)
265 {
266         int i;
267
268         printk("[ ");
269         for (i = 0; i < len; i++)
270                 printk("%x ", x[i]);
271         printk("]\n");
272 }
273
274 static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command)
275 {
276         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
277         idescsi_pc_t   *pc;
278         struct request *rq;
279         u8             *buf;
280
281         /* stuff a sense request in front of our current request */
282         pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC);
283         rq = kmalloc (sizeof (struct request), GFP_ATOMIC);
284         buf = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
285         if (pc == NULL || rq == NULL || buf == NULL) {
286                 if (pc) kfree(pc);
287                 if (rq) kfree(rq);
288                 if (buf) kfree(buf);
289                 return -ENOMEM;
290         }
291         memset (pc, 0, sizeof (idescsi_pc_t));
292         memset (buf, 0, SCSI_SENSE_BUFFERSIZE);
293         ide_init_drive_cmd(rq);
294         rq->special = (char *) pc;
295         pc->rq = rq;
296         pc->buffer = buf;
297         pc->c[0] = REQUEST_SENSE;
298         pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE;
299         rq->flags = REQ_SENSE;
300         pc->timeout = jiffies + WAIT_READY;
301         /* NOTE! Save the failed packet command in "rq->buffer" */
302         rq->buffer = (void *) failed_command->special;
303         pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd;
304         if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
305                 printk ("ide-scsi: %s: queue cmd = ", drive->name);
306                 hexdump(pc->c, 6);
307         }
308         return ide_do_drive_cmd(drive, rq, ide_preempt);
309 }
310
311 ide_startstop_t idescsi_atapi_error (ide_drive_t *drive, const char *msg, byte stat)
312 {
313         struct request *rq;
314         byte err;
315
316         err = ide_dump_atapi_status(drive, msg, stat);
317
318         if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
319                 return ide_stopped;
320
321         if (HWIF(drive)->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
322                 /* force an abort */
323                 HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG);
324
325         rq->errors++;
326         DRIVER(drive)->end_request(drive, 0, 0);
327         return ide_stopped;
328 }
329
330 ide_startstop_t idescsi_atapi_abort (ide_drive_t *drive, const char *msg)
331 {
332         struct request *rq;
333
334         if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
335                return ide_stopped;
336
337 #if IDESCSI_DEBUG_LOG
338         printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n",
339                         ((idescsi_pc_t *) rq->special)->scsi_cmd->serial_number);
340 #endif
341         rq->errors |= ERROR_MAX;
342         DRIVER(drive)->end_request(drive, 0, 0);
343         return ide_stopped;
344 }
345
346 static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
347 {
348         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
349         struct request *rq = HWGROUP(drive)->rq;
350         idescsi_pc_t *pc = (idescsi_pc_t *) rq->special;
351         int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
352         struct Scsi_Host *host;
353         u8 *scsi_buf;
354         unsigned long flags;
355
356         if (!(rq->flags & (REQ_SPECIAL|REQ_SENSE))) {
357                 ide_end_request(drive, uptodate, nrsecs);
358                 return 0;
359         }
360         ide_end_drive_cmd (drive, 0, 0);
361         if (rq->flags & REQ_SENSE) {
362                 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer;
363                 if (log) {
364                         printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
365                         hexdump(pc->buffer,16);
366                 }
367                 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE);
368                 kfree(pc->buffer);
369                 kfree(pc);
370                 kfree(rq);
371                 pc = opc;
372                 rq = pc->rq;
373                 pc->scsi_cmd->result = (CHECK_CONDITION << 1) |
374                                         ((test_bit(PC_TIMEDOUT, &pc->flags)?DID_TIME_OUT:DID_OK) << 16);
375         } else if (test_bit(PC_TIMEDOUT, &pc->flags)) {
376                 if (log)
377                         printk (KERN_WARNING "ide-scsi: %s: timed out for %lu\n",
378                                         drive->name, pc->scsi_cmd->serial_number);
379                 pc->scsi_cmd->result = DID_TIME_OUT << 16;
380         } else if (rq->errors >= ERROR_MAX) {
381                 pc->scsi_cmd->result = DID_ERROR << 16;
382                 if (log)
383                         printk ("ide-scsi: %s: I/O error for %lu\n", drive->name, pc->scsi_cmd->serial_number);
384         } else if (rq->errors) {
385                 if (log)
386                         printk ("ide-scsi: %s: check condition for %lu\n", drive->name, pc->scsi_cmd->serial_number);
387                 if (!idescsi_check_condition(drive, rq))
388                         /* we started a request sense, so we'll be back, exit for now */
389                         return 0;
390                 pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
391         } else {
392                 pc->scsi_cmd->result = DID_OK << 16;
393                 idescsi_transform_pc2 (drive, pc);
394                 if (log) {
395                         printk ("ide-scsi: %s: suc %lu", drive->name, pc->scsi_cmd->serial_number);
396                         if (!test_bit(PC_WRITING, &pc->flags) && pc->actually_transferred && pc->actually_transferred <= 1024 && pc->buffer) {
397                                 printk(", rst = ");
398                                 scsi_buf = pc->scsi_cmd->request_buffer;
399                                 hexdump(scsi_buf, min_t(unsigned, 16, pc->scsi_cmd->request_bufflen));
400                         } else printk("\n");
401                 }
402         }
403         host = pc->scsi_cmd->device->host;
404         spin_lock_irqsave(host->host_lock, flags);
405         pc->done(pc->scsi_cmd);
406         spin_unlock_irqrestore(host->host_lock, flags);
407         idescsi_free_bio(rq->bio);
408         kfree(pc);
409         kfree(rq);
410         scsi->pc = NULL;
411         return 0;
412 }
413
414 static inline unsigned long get_timeout(idescsi_pc_t *pc)
415 {
416         return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
417 }
418
419 static int idescsi_expiry(ide_drive_t *drive)
420 {
421         idescsi_scsi_t *scsi = drive->driver_data;
422         idescsi_pc_t   *pc   = scsi->pc;
423
424 #if IDESCSI_DEBUG_LOG
425         printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies);
426 #endif
427         set_bit(PC_TIMEDOUT, &pc->flags);
428
429         return 0;                                       /* we do not want the ide subsystem to retry */
430 }
431
432 /*
433  *      Our interrupt handler.
434  */
435 static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
436 {
437         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
438         idescsi_pc_t *pc=scsi->pc;
439         struct request *rq = pc->rq;
440         atapi_bcount_t bcount;
441         atapi_status_t status;
442         atapi_ireason_t ireason;
443         atapi_feature_t feature;
444
445         unsigned int temp;
446
447 #if IDESCSI_DEBUG_LOG
448         printk (KERN_INFO "ide-scsi: Reached idescsi_pc_intr interrupt handler\n");
449 #endif /* IDESCSI_DEBUG_LOG */
450
451         if (test_bit(PC_TIMEDOUT, &pc->flags)){
452 #if IDESCSI_DEBUG_LOG
453                 printk(KERN_WARNING "idescsi_pc_intr: got timed out packet  %lu at %lu\n",
454                                 pc->scsi_cmd->serial_number, jiffies);
455 #endif
456                 /* end this request now - scsi should retry it*/
457                 idescsi_end_request (drive, 1, 0);
458                 return ide_stopped;
459         }
460         if (test_and_clear_bit (PC_DMA_IN_PROGRESS, &pc->flags)) {
461 #if IDESCSI_DEBUG_LOG
462                 printk ("ide-scsi: %s: DMA complete\n", drive->name);
463 #endif /* IDESCSI_DEBUG_LOG */
464                 pc->actually_transferred=pc->request_transfer;
465                 (void) HWIF(drive)->ide_dma_end(drive);
466         }
467
468         feature.all = 0;
469         /* Clear the interrupt */
470         status.all = HWIF(drive)->INB(IDE_STATUS_REG);
471
472         if (!status.b.drq) {
473                 /* No more interrupts */
474                 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
475                         printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred);
476                 local_irq_enable();
477                 if (status.b.check)
478                         rq->errors++;
479                 idescsi_end_request (drive, 1, 0);
480                 return ide_stopped;
481         }
482         bcount.b.low    = HWIF(drive)->INB(IDE_BCOUNTL_REG);
483         bcount.b.high   = HWIF(drive)->INB(IDE_BCOUNTH_REG);
484         ireason.all     = HWIF(drive)->INB(IDE_IREASON_REG);
485
486         if (ireason.b.cod) {
487                 printk(KERN_ERR "ide-scsi: CoD != 0 in idescsi_pc_intr\n");
488                 return ide_do_reset (drive);
489         }
490         if (ireason.b.io) {
491                 temp = pc->actually_transferred + bcount.all;
492                 if (temp > pc->request_transfer) {
493                         if (temp > pc->buffer_size) {
494                                 printk(KERN_ERR "ide-scsi: The scsi wants to "
495                                         "send us more data than expected "
496                                         "- discarding data\n");
497                                 temp = pc->buffer_size - pc->actually_transferred;
498                                 if (temp) {
499                                         clear_bit(PC_WRITING, &pc->flags);
500                                         if (pc->sg)
501                                                 idescsi_input_buffers(drive, pc, temp);
502                                         else
503                                                 atapi_input_bytes(drive, pc->current_position, temp);
504                                         printk(KERN_ERR "ide-scsi: transferred %d of %d bytes\n", temp, bcount.all);
505                                 }
506                                 pc->actually_transferred += temp;
507                                 pc->current_position += temp;
508                                 idescsi_discard_data(drive, bcount.all - temp);
509                                 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
510                                 return ide_started;
511                         }
512 #if IDESCSI_DEBUG_LOG
513                         printk (KERN_NOTICE "ide-scsi: The scsi wants to send us more data than expected - allowing transfer\n");
514 #endif /* IDESCSI_DEBUG_LOG */
515                 }
516         }
517         if (ireason.b.io) {
518                 clear_bit(PC_WRITING, &pc->flags);
519                 if (pc->sg)
520                         idescsi_input_buffers(drive, pc, bcount.all);
521                 else
522                         HWIF(drive)->atapi_input_bytes(drive, pc->current_position, bcount.all);
523         } else {
524                 set_bit(PC_WRITING, &pc->flags);
525                 if (pc->sg)
526                         idescsi_output_buffers (drive, pc, bcount.all);
527                 else
528                         HWIF(drive)->atapi_output_bytes(drive, pc->current_position, bcount.all);
529         }
530         /* Update the current position */
531         pc->actually_transferred += bcount.all;
532         pc->current_position += bcount.all;
533
534         /* And set the interrupt handler again */
535         ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
536         return ide_started;
537 }
538
539 static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
540 {
541         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
542         idescsi_pc_t *pc = scsi->pc;
543         atapi_ireason_t ireason;
544         ide_startstop_t startstop;
545
546         if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) {
547                 printk(KERN_ERR "ide-scsi: Strange, packet command "
548                         "initiated yet DRQ isn't asserted\n");
549                 return startstop;
550         }
551         ireason.all     = HWIF(drive)->INB(IDE_IREASON_REG);
552         if (!ireason.b.cod || ireason.b.io) {
553                 printk(KERN_ERR "ide-scsi: (IO,CoD) != (0,1) while "
554                                 "issuing a packet command\n");
555                 return ide_do_reset (drive);
556         }
557         if (HWGROUP(drive)->handler != NULL)
558                 BUG();
559         /* Set the interrupt routine */
560         ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
561         /* Send the actual packet */
562         atapi_output_bytes(drive, scsi->pc->c, 12);
563         if (test_bit (PC_DMA_OK, &pc->flags)) {
564                 set_bit (PC_DMA_IN_PROGRESS, &pc->flags);
565                 (void) (HWIF(drive)->ide_dma_begin(drive));
566         }
567         return ide_started;
568 }
569
570 /*
571  *      Issue a packet command
572  */
573 static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
574 {
575         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
576         atapi_feature_t feature;
577         atapi_bcount_t bcount;
578         struct request *rq = pc->rq;
579
580         scsi->pc=pc;                                                    /* Set the current packet command */
581         pc->actually_transferred=0;                                     /* We haven't transferred any data yet */
582         pc->current_position=pc->buffer;
583         bcount.all = min(pc->request_transfer, 63 * 1024);              /* Request to transfer the entire buffer at once */
584
585         feature.all = 0;
586         if (drive->using_dma && rq->bio) {
587                 if (test_bit(PC_WRITING, &pc->flags))
588                         feature.b.dma = !HWIF(drive)->ide_dma_write(drive);
589                 else
590                         feature.b.dma = !HWIF(drive)->ide_dma_read(drive);
591         }
592
593         SELECT_DRIVE(drive);
594         if (IDE_CONTROL_REG)
595                 HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
596
597         HWIF(drive)->OUTB(feature.all, IDE_FEATURE_REG);
598         HWIF(drive)->OUTB(bcount.b.high, IDE_BCOUNTH_REG);
599         HWIF(drive)->OUTB(bcount.b.low, IDE_BCOUNTL_REG);
600
601         if (feature.b.dma)
602                 set_bit(PC_DMA_OK, &pc->flags);
603
604         if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
605                 if (HWGROUP(drive)->handler != NULL)
606                         BUG();
607                 ide_set_handler(drive, &idescsi_transfer_pc,
608                                 get_timeout(pc), idescsi_expiry);
609                 /* Issue the packet command */
610                 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
611                 return ide_started;
612         } else {
613                 /* Issue the packet command */
614                 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG);
615                 return idescsi_transfer_pc(drive);
616         }
617 }
618
619 /*
620  *      idescsi_do_request is our request handling function.
621  */
622 static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
623 {
624 #if IDESCSI_DEBUG_LOG
625         printk (KERN_INFO "rq_status: %d, dev: %s, cmd: %x, errors: %d\n",rq->rq_status, rq->rq_disk->disk_name,rq->cmd[0],rq->errors);
626         printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors);
627 #endif /* IDESCSI_DEBUG_LOG */
628
629         if (rq->flags & (REQ_SPECIAL|REQ_SENSE)) {
630                 return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special);
631         }
632         blk_dump_rq_flags(rq, "ide-scsi: unsup command");
633         idescsi_end_request (drive, 0, 0);
634         return ide_stopped;
635 }
636
637 static void idescsi_add_settings(ide_drive_t *drive)
638 {
639         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
640
641 /*
642  *                      drive   setting name    read/write      ioctl   ioctl           data type       min     max     mul_factor      div_factor      data pointer            set function
643  */
644         ide_add_setting(drive,  "bios_cyl",     SETTING_RW,     -1,     -1,             TYPE_INT,       0,      1023,   1,              1,              &drive->bios_cyl,       NULL);
645         ide_add_setting(drive,  "bios_head",    SETTING_RW,     -1,     -1,             TYPE_BYTE,      0,      255,    1,              1,              &drive->bios_head,      NULL);
646         ide_add_setting(drive,  "bios_sect",    SETTING_RW,     -1,     -1,             TYPE_BYTE,      0,      63,     1,              1,              &drive->bios_sect,      NULL);
647         ide_add_setting(drive,  "transform",    SETTING_RW,     -1,     -1,             TYPE_INT,       0,      3,      1,              1,              &scsi->transform,       NULL);
648         ide_add_setting(drive,  "log",          SETTING_RW,     -1,     -1,             TYPE_INT,       0,      1,      1,              1,              &scsi->log,             NULL);
649 }
650
651 /*
652  *      Driver initialization.
653  */
654 static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
655 {
656         DRIVER(drive)->busy++;
657         drive->ready_stat = 0;
658         if (drive->id && (drive->id->config & 0x0060) == 0x20)
659                 set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
660         set_bit(IDESCSI_TRANSFORM, &scsi->transform);
661         clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
662 #if IDESCSI_DEBUG_LOG
663         set_bit(IDESCSI_LOG_CMD, &scsi->log);
664 #endif /* IDESCSI_DEBUG_LOG */
665         idescsi_add_settings(drive);
666         DRIVER(drive)->busy--;
667 }
668
669 static int idescsi_cleanup (ide_drive_t *drive)
670 {
671         struct Scsi_Host *scsihost = drive->driver_data;
672
673         if (ide_unregister_subdriver(drive))
674                 return 1;
675         
676         /* FIXME?: Are these two statements necessary? */
677         drive->driver_data = NULL;
678         drive->disk->fops = ide_fops;
679
680         scsi_remove_host(scsihost);
681         scsi_host_put(scsihost);
682         return 0;
683 }
684
685 static int idescsi_attach(ide_drive_t *drive);
686
687 /*
688  *      IDE subdriver functions, registered with ide.c
689  */
690 static ide_driver_t idescsi_driver = {
691         .owner                  = THIS_MODULE,
692         .name                   = "ide-scsi",
693         .version                = IDESCSI_VERSION,
694         .media                  = ide_scsi,
695         .busy                   = 0,
696         .supports_dsc_overlap   = 0,
697         .attach                 = idescsi_attach,
698         .cleanup                = idescsi_cleanup,
699         .do_request             = idescsi_do_request,
700         .end_request            = idescsi_end_request,
701         .error                  = idescsi_atapi_error,
702         .abort                  = idescsi_atapi_abort,
703         .drives                 = LIST_HEAD_INIT(idescsi_driver.drives),
704 };
705
706 static int idescsi_ide_open(struct inode *inode, struct file *filp)
707 {
708         ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
709         drive->usage++;
710         return 0;
711 }
712
713 static int idescsi_ide_release(struct inode *inode, struct file *filp)
714 {
715         ide_drive_t *drive = inode->i_bdev->bd_disk->private_data;
716         drive->usage--;
717         return 0;
718 }
719
720 static int idescsi_ide_ioctl(struct inode *inode, struct file *file,
721                         unsigned int cmd, unsigned long arg)
722 {
723         struct block_device *bdev = inode->i_bdev;
724         return generic_ide_ioctl(bdev, cmd, arg);
725 }
726
727 static struct block_device_operations idescsi_ops = {
728         .owner          = THIS_MODULE,
729         .open           = idescsi_ide_open,
730         .release        = idescsi_ide_release,
731         .ioctl          = idescsi_ide_ioctl,
732 };
733
734 static int idescsi_attach(ide_drive_t *drive);
735
736 static int idescsi_slave_configure(Scsi_Device * sdp)
737 {
738         /* Configure detected device */
739         scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun);
740         return 0;
741 }
742
743 static const char *idescsi_info (struct Scsi_Host *host)
744 {
745         return "SCSI host adapter emulation for IDE ATAPI devices";
746 }
747
748 static int idescsi_ioctl (Scsi_Device *dev, int cmd, void *arg)
749 {
750         idescsi_scsi_t *scsi = scsihost_to_idescsi(dev->host);
751
752         if (cmd == SG_SET_TRANSFORM) {
753                 if (arg)
754                         set_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
755                 else
756                         clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
757                 return 0;
758         } else if (cmd == SG_GET_TRANSFORM)
759                 return put_user(test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform), (int *) arg);
760         return -EINVAL;
761 }
762
763 static inline struct bio *idescsi_kmalloc_bio (int count)
764 {
765         struct bio *bh, *bhp, *first_bh;
766
767         if ((first_bh = bhp = bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
768                 goto abort;
769         bio_init(bh);
770         bh->bi_vcnt = 1;
771         while (--count) {
772                 if ((bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
773                         goto abort;
774                 bio_init(bh);
775                 bh->bi_vcnt = 1;
776                 bhp->bi_next = bh;
777                 bhp = bh;
778                 bh->bi_next = NULL;
779         }
780         return first_bh;
781 abort:
782         idescsi_free_bio (first_bh);
783         return NULL;
784 }
785
786 static inline int idescsi_set_direction (idescsi_pc_t *pc)
787 {
788         switch (pc->c[0]) {
789                 case READ_6: case READ_10: case READ_12:
790                         clear_bit (PC_WRITING, &pc->flags);
791                         return 0;
792                 case WRITE_6: case WRITE_10: case WRITE_12:
793                         set_bit (PC_WRITING, &pc->flags);
794                         return 0;
795                 default:
796                         return 1;
797         }
798 }
799
800 static inline struct bio *idescsi_dma_bio(ide_drive_t *drive, idescsi_pc_t *pc)
801 {
802         struct bio *bh = NULL, *first_bh = NULL;
803         int segments = pc->scsi_cmd->use_sg;
804         struct scatterlist *sg = pc->scsi_cmd->request_buffer;
805
806         if (!drive->using_dma || !pc->request_transfer || pc->request_transfer % 1024)
807                 return NULL;
808         if (idescsi_set_direction(pc))
809                 return NULL;
810         if (segments) {
811                 if ((first_bh = bh = idescsi_kmalloc_bio (segments)) == NULL)
812                         return NULL;
813 #if IDESCSI_DEBUG_LOG
814                 printk ("ide-scsi: %s: building DMA table, %d segments, %dkB total\n", drive->name, segments, pc->request_transfer >> 10);
815 #endif /* IDESCSI_DEBUG_LOG */
816                 while (segments--) {
817                         bh->bi_io_vec[0].bv_page = sg->page;
818                         bh->bi_io_vec[0].bv_len = sg->length;
819                         bh->bi_io_vec[0].bv_offset = sg->offset;
820                         bh->bi_size = sg->length;
821                         bh = bh->bi_next;
822                         sg++;
823                 }
824         } else {
825                 if ((first_bh = bh = idescsi_kmalloc_bio (1)) == NULL)
826                         return NULL;
827 #if IDESCSI_DEBUG_LOG
828                 printk ("ide-scsi: %s: building DMA table for a single buffer (%dkB)\n", drive->name, pc->request_transfer >> 10);
829 #endif /* IDESCSI_DEBUG_LOG */
830                 bh->bi_io_vec[0].bv_page = virt_to_page(pc->scsi_cmd->request_buffer);
831                 bh->bi_io_vec[0].bv_offset = offset_in_page(pc->scsi_cmd->request_buffer);
832                 bh->bi_io_vec[0].bv_len = pc->request_transfer;
833                 bh->bi_size = pc->request_transfer;
834         }
835         return first_bh;
836 }
837
838 static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)
839 {
840         idescsi_scsi_t *scsi = drive_to_idescsi(drive);
841
842         /* this was a layering violation and we can't support it
843            anymore, sorry. */
844 #if 0
845         struct gendisk *disk = cmd->request->rq_disk;
846
847         if (disk) {
848                 struct Scsi_Device_Template **p = disk->private_data;
849                 if (strcmp((*p)->scsi_driverfs_driver.name, "sg") == 0)
850                         return test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
851         }
852 #endif
853         return test_bit(IDESCSI_TRANSFORM, &scsi->transform);
854 }
855
856 static int idescsi_queue (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
857 {
858         struct Scsi_Host *host = cmd->device->host;
859         idescsi_scsi_t *scsi = scsihost_to_idescsi(host);
860         ide_drive_t *drive = scsi->drive;
861         struct request *rq = NULL;
862         idescsi_pc_t *pc = NULL;
863
864         if (!drive) {
865                 printk (KERN_ERR "ide-scsi: drive id %d not present\n", cmd->device->id);
866                 goto abort;
867         }
868         scsi = drive_to_idescsi(drive);
869         pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC);
870         rq = kmalloc (sizeof (struct request), GFP_ATOMIC);
871         if (rq == NULL || pc == NULL) {
872                 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
873                 goto abort;
874         }
875
876         memset (pc->c, 0, 12);
877         pc->flags = 0;
878         pc->rq = rq;
879         memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
880         if (cmd->use_sg) {
881                 pc->buffer = NULL;
882                 pc->sg = cmd->request_buffer;
883         } else {
884                 pc->buffer = cmd->request_buffer;
885                 pc->sg = NULL;
886         }
887         pc->b_count = 0;
888         pc->request_transfer = pc->buffer_size = cmd->request_bufflen;
889         pc->scsi_cmd = cmd;
890         pc->done = done;
891         pc->timeout = jiffies + cmd->timeout_per_command;
892
893         if (should_transform(drive, cmd))
894                 set_bit(PC_TRANSFORM, &pc->flags);
895         idescsi_transform_pc1 (drive, pc);
896
897         if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
898                 printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
899                 hexdump(cmd->cmnd, cmd->cmd_len);
900                 if (memcmp(pc->c, cmd->cmnd, cmd->cmd_len)) {
901                         printk ("ide-scsi: %s: que %lu, tsl = ", drive->name, cmd->serial_number);
902                         hexdump(pc->c, 12);
903                 }
904         }
905
906         ide_init_drive_cmd (rq);
907         rq->special = (char *) pc;
908         rq->bio = idescsi_dma_bio (drive, pc);
909         rq->flags = REQ_SPECIAL;
910         spin_unlock_irq(host->host_lock);
911         (void) ide_do_drive_cmd (drive, rq, ide_end);
912         spin_lock_irq(host->host_lock);
913         return 0;
914 abort:
915         if (pc) kfree (pc);
916         if (rq) kfree (rq);
917         cmd->result = DID_ERROR << 16;
918         done(cmd);
919         return 1;
920 }
921
922 static int idescsi_eh_abort (Scsi_Cmnd *cmd)
923 {
924         idescsi_scsi_t *scsi  = scsihost_to_idescsi(cmd->device->host);
925         ide_drive_t    *drive = scsi->drive;
926         int             busy;
927         int             ret   = FAILED;
928
929         /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */
930
931         if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
932                 printk (KERN_WARNING "ide-scsi: abort called for %lu\n", cmd->serial_number);
933
934         if (!drive) {
935                 printk (KERN_WARNING "ide-scsi: Drive not set in idescsi_eh_abort\n");
936                 WARN_ON(1);
937                 goto no_drive;
938         }
939
940         /* First give it some more time, how much is "right" is hard to say :-( */
941
942         busy = ide_wait_not_busy(HWIF(drive), 100);     /* FIXME - uses mdelay which causes latency? */
943         if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
944                 printk (KERN_WARNING "ide-scsi: drive did%s become ready\n", busy?" not":"");
945
946         spin_lock_irq(&ide_lock);
947
948         /* If there is no pc running we're done (our interrupt took care of it) */
949         if (!scsi->pc) {
950                 ret = SUCCESS;
951                 goto ide_unlock;
952         }
953
954         /* It's somewhere in flight. Does ide subsystem agree? */
955         if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
956             elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) {
957                 /*
958                  * FIXME - not sure this condition can ever occur
959                  */
960                 printk (KERN_ERR "ide-scsi: cmd aborted!\n");
961
962                 idescsi_free_bio(scsi->pc->rq->bio);
963                 if (scsi->pc->rq->flags & REQ_SENSE)
964                         kfree(scsi->pc->buffer);
965                 kfree(scsi->pc->rq);
966                 kfree(scsi->pc);
967                 scsi->pc = NULL;
968
969                 ret = SUCCESS;
970         }
971
972 ide_unlock:
973         spin_unlock_irq(&ide_lock);
974 no_drive:
975         if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
976                 printk (KERN_WARNING "ide-scsi: abort returns %s\n", ret == SUCCESS?"success":"failed");
977
978         return ret;
979 }
980
981 static int idescsi_eh_reset (Scsi_Cmnd *cmd)
982 {
983         struct request *req;
984         idescsi_scsi_t *scsi  = scsihost_to_idescsi(cmd->device->host);
985         ide_drive_t    *drive = scsi->drive;
986         int             ready = 0;
987         int             ret   = SUCCESS;
988
989         /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */
990
991         if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
992                 printk (KERN_WARNING "ide-scsi: reset called for %lu\n", cmd->serial_number);
993
994         if (!drive) {
995                 printk (KERN_WARNING "ide-scsi: Drive not set in idescsi_eh_reset\n");
996                 WARN_ON(1);
997                 return FAILED;
998         }
999
1000         spin_lock_irq(&ide_lock);
1001
1002         if (!scsi->pc || (req = scsi->pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) {
1003                 printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n");
1004                 spin_unlock(&ide_lock);
1005                 return FAILED;
1006         }
1007
1008         /* kill current request */
1009         blkdev_dequeue_request(req);
1010         end_that_request_last(req);
1011         idescsi_free_bio(req->bio);
1012         if (req->flags & REQ_SENSE)
1013                 kfree(scsi->pc->buffer);
1014         kfree(scsi->pc);
1015         scsi->pc = NULL;
1016         kfree(req);
1017
1018         /* now nuke the drive queue */
1019         while ((req = elv_next_request(drive->queue))) {
1020                 blkdev_dequeue_request(req);
1021                 end_that_request_last(req);
1022         }
1023
1024         HWGROUP(drive)->rq = NULL;
1025         HWGROUP(drive)->handler = NULL;
1026         HWGROUP(drive)->busy = 1;               /* will set this to zero when ide reset finished */
1027         spin_unlock_irq(&ide_lock);
1028
1029         ide_do_reset(drive);
1030
1031         /* ide_do_reset starts a polling handler which restarts itself every 50ms until the reset finishes */
1032
1033         do {
1034                 set_current_state(TASK_UNINTERRUPTIBLE);
1035                 spin_unlock_irq(cmd->device->host->host_lock);
1036                 schedule_timeout(HZ/20);
1037                 spin_lock_irq(cmd->device->host->host_lock);
1038         } while ( HWGROUP(drive)->handler );
1039
1040         ready = drive_is_ready(drive);
1041         HWGROUP(drive)->busy--;
1042         if (!ready) {
1043                 printk (KERN_ERR "ide-scsi: reset failed!\n");
1044                 ret = FAILED;
1045         }
1046
1047         return ret;
1048 }
1049
1050 static int idescsi_bios(struct scsi_device *sdev, struct block_device *bdev,
1051                 sector_t capacity, int *parm)
1052 {
1053         idescsi_scsi_t *idescsi = scsihost_to_idescsi(sdev->host);
1054         ide_drive_t *drive = idescsi->drive;
1055
1056         if (drive->bios_cyl && drive->bios_head && drive->bios_sect) {
1057                 parm[0] = drive->bios_head;
1058                 parm[1] = drive->bios_sect;
1059                 parm[2] = drive->bios_cyl;
1060         }
1061         return 0;
1062 }
1063
1064 static Scsi_Host_Template idescsi_template = {
1065         .module                 = THIS_MODULE,
1066         .name                   = "idescsi",
1067         .info                   = idescsi_info,
1068         .slave_configure        = idescsi_slave_configure,
1069         .ioctl                  = idescsi_ioctl,
1070         .queuecommand           = idescsi_queue,
1071         .eh_abort_handler       = idescsi_eh_abort,
1072         .eh_host_reset_handler  = idescsi_eh_reset,
1073         .bios_param             = idescsi_bios,
1074         .can_queue              = 40,
1075         .this_id                = -1,
1076         .sg_tablesize           = 256,
1077         .cmd_per_lun            = 5,
1078         .max_sectors            = 128,
1079         .use_clustering         = DISABLE_CLUSTERING,
1080         .emulated               = 1,
1081         .proc_name              = "ide-scsi",
1082 };
1083
1084 static int idescsi_attach(ide_drive_t *drive)
1085 {
1086         idescsi_scsi_t *idescsi;
1087         struct Scsi_Host *host;
1088         static int warned;
1089         int err;
1090
1091         if (!warned && drive->media == ide_cdrom) {
1092                 printk(KERN_WARNING "ide-scsi is deprecated for cd burning! Use ide-cd and give dev=/dev/hdX as device\n");
1093                 warned = 1;
1094         }
1095
1096         if (!strstr("ide-scsi", drive->driver_req) ||
1097             !drive->present ||
1098             drive->media == ide_disk ||
1099             !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t))))
1100                 return 1;
1101
1102         host->max_id = 1;
1103
1104 #if IDESCSI_DEBUG_LOG
1105         if (drive->id->last_lun)
1106                 printk(KERN_NOTICE "%s: id->last_lun=%u\n", drive->name, drive->id->last_lun);
1107 #endif
1108         if ((drive->id->last_lun & 0x7) != 7)
1109                 host->max_lun = (drive->id->last_lun & 0x7) + 1;
1110         else
1111                 host->max_lun = 1;
1112
1113         drive->driver_data = host;
1114         idescsi = scsihost_to_idescsi(host);
1115         idescsi->drive = drive;
1116         err = ide_register_subdriver(drive, &idescsi_driver);
1117         if (!err) {
1118                 idescsi_setup (drive, idescsi);
1119                 drive->disk->fops = &idescsi_ops;
1120                 err = scsi_add_host(host, &drive->gendev);
1121                 if (!err) {
1122                         scsi_scan_host(host);
1123                         return 0;
1124                 }
1125                 /* fall through on error */
1126                 ide_unregister_subdriver(drive);
1127         }
1128
1129         scsi_host_put(host);
1130         return err;
1131 }
1132
1133 static int __init init_idescsi_module(void)
1134 {
1135         return ide_register_driver(&idescsi_driver);
1136 }
1137
1138 static void __exit exit_idescsi_module(void)
1139 {
1140         ide_unregister_driver(&idescsi_driver);
1141 }
1142
1143 module_init(init_idescsi_module);
1144 module_exit(exit_idescsi_module);
1145 MODULE_LICENSE("GPL");