Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 2 | * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il> |
| 3 | * Copyright (C) 2004-2005 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | /* |
| 7 | * Emulation of a SCSI host adapter for IDE ATAPI devices. |
| 8 | * |
| 9 | * With this driver, one can use the Linux SCSI drivers instead of the |
| 10 | * native IDE ATAPI drivers. |
| 11 | * |
| 12 | * Ver 0.1 Dec 3 96 Initial version. |
| 13 | * Ver 0.2 Jan 26 97 Fixed bug in cleanup_module() and added emulation |
| 14 | * of MODE_SENSE_6/MODE_SELECT_6 for cdroms. Thanks |
| 15 | * to Janos Farkas for pointing this out. |
| 16 | * Avoid using bitfields in structures for m68k. |
| 17 | * Added Scatter/Gather and DMA support. |
| 18 | * Ver 0.4 Dec 7 97 Add support for ATAPI PD/CD drives. |
| 19 | * Use variable timeout for each command. |
| 20 | * Ver 0.5 Jan 2 98 Fix previous PD/CD support. |
| 21 | * Allow disabling of SCSI-6 to SCSI-10 transformation. |
| 22 | * Ver 0.6 Jan 27 98 Allow disabling of SCSI command translation layer |
| 23 | * for access through /dev/sg. |
| 24 | * Fix MODE_SENSE_6/MODE_SELECT_6/INQUIRY translation. |
| 25 | * Ver 0.7 Dec 04 98 Ignore commands where lun != 0 to avoid multiple |
| 26 | * detection of devices with CONFIG_SCSI_MULTI_LUN |
| 27 | * Ver 0.8 Feb 05 99 Optical media need translation too. Reverse 0.7. |
| 28 | * Ver 0.9 Jul 04 99 Fix a bug in SG_SET_TRANSFORM. |
| 29 | * Ver 0.91 Jun 10 02 Fix "off by one" error in transforms |
| 30 | * Ver 0.92 Dec 31 02 Implement new SCSI mid level API |
| 31 | */ |
| 32 | |
| 33 | #define IDESCSI_VERSION "0.92" |
| 34 | |
| 35 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/types.h> |
| 37 | #include <linux/string.h> |
| 38 | #include <linux/kernel.h> |
| 39 | #include <linux/mm.h> |
| 40 | #include <linux/ioport.h> |
| 41 | #include <linux/blkdev.h> |
| 42 | #include <linux/errno.h> |
| 43 | #include <linux/hdreg.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/ide.h> |
| 46 | #include <linux/scatterlist.h> |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 47 | #include <linux/delay.h> |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Jiri Slaby | 1977f03 | 2007-10-18 23:40:25 -0700 | [diff] [blame] | 49 | #include <linux/bitops.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/uaccess.h> |
| 53 | |
| 54 | #include <scsi/scsi.h> |
| 55 | #include <scsi/scsi_cmnd.h> |
| 56 | #include <scsi/scsi_device.h> |
| 57 | #include <scsi/scsi_host.h> |
| 58 | #include <scsi/scsi_tcq.h> |
| 59 | #include <scsi/sg.h> |
| 60 | |
| 61 | #define IDESCSI_DEBUG_LOG 0 |
| 62 | |
| 63 | typedef struct idescsi_pc_s { |
| 64 | u8 c[12]; /* Actual packet bytes */ |
| 65 | int request_transfer; /* Bytes to transfer */ |
| 66 | int actually_transferred; /* Bytes actually transferred */ |
| 67 | int buffer_size; /* Size of our data buffer */ |
| 68 | struct request *rq; /* The corresponding request */ |
| 69 | u8 *buffer; /* Data buffer */ |
| 70 | u8 *current_position; /* Pointer into the above buffer */ |
| 71 | struct scatterlist *sg; /* Scatter gather table */ |
Jens Axboe | c79d88b | 2007-10-17 13:16:35 +0200 | [diff] [blame] | 72 | unsigned int sg_cnt; /* Number of entries in sg */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | int b_count; /* Bytes transferred from current entry */ |
| 74 | struct scsi_cmnd *scsi_cmd; /* SCSI command */ |
| 75 | void (*done)(struct scsi_cmnd *); /* Scsi completion routine */ |
| 76 | unsigned long flags; /* Status/Action flags */ |
| 77 | unsigned long timeout; /* Command timeout */ |
| 78 | } idescsi_pc_t; |
| 79 | |
| 80 | /* |
| 81 | * Packet command status bits. |
| 82 | */ |
| 83 | #define PC_DMA_IN_PROGRESS 0 /* 1 while DMA in progress */ |
| 84 | #define PC_WRITING 1 /* Data direction */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define PC_TIMEDOUT 3 /* command timed out */ |
| 86 | #define PC_DMA_OK 4 /* Use DMA */ |
| 87 | |
| 88 | /* |
| 89 | * SCSI command transformation layer |
| 90 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | #define IDESCSI_SG_TRANSFORM 1 /* /dev/sg transformation */ |
| 92 | |
| 93 | /* |
| 94 | * Log flags |
| 95 | */ |
| 96 | #define IDESCSI_LOG_CMD 0 /* Log SCSI commands */ |
| 97 | |
| 98 | typedef struct ide_scsi_obj { |
| 99 | ide_drive_t *drive; |
| 100 | ide_driver_t *driver; |
| 101 | struct gendisk *disk; |
| 102 | struct Scsi_Host *host; |
| 103 | |
| 104 | idescsi_pc_t *pc; /* Current packet command */ |
| 105 | unsigned long flags; /* Status/Action flags */ |
| 106 | unsigned long transform; /* SCSI cmd translation layer */ |
| 107 | unsigned long log; /* log flags */ |
| 108 | } idescsi_scsi_t; |
| 109 | |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 110 | static DEFINE_MUTEX(idescsi_ref_mutex); |
Alan Cox | aaeab80 | 2006-12-06 20:39:33 -0800 | [diff] [blame] | 111 | static int idescsi_nocd; /* Set by module param to skip cd */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | #define ide_scsi_g(disk) \ |
| 114 | container_of((disk)->private_data, struct ide_scsi_obj, driver) |
| 115 | |
| 116 | static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk) |
| 117 | { |
| 118 | struct ide_scsi_obj *scsi = NULL; |
| 119 | |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 120 | mutex_lock(&idescsi_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | scsi = ide_scsi_g(disk); |
| 122 | if (scsi) |
| 123 | scsi_host_get(scsi->host); |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 124 | mutex_unlock(&idescsi_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return scsi; |
| 126 | } |
| 127 | |
| 128 | static void ide_scsi_put(struct ide_scsi_obj *scsi) |
| 129 | { |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 130 | mutex_lock(&idescsi_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | scsi_host_put(scsi->host); |
Jes Sorensen | e723ccd | 2006-03-23 03:00:22 -0800 | [diff] [blame] | 132 | mutex_unlock(&idescsi_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static inline idescsi_scsi_t *scsihost_to_idescsi(struct Scsi_Host *host) |
| 136 | { |
| 137 | return (idescsi_scsi_t*) (&host[1]); |
| 138 | } |
| 139 | |
| 140 | static inline idescsi_scsi_t *drive_to_idescsi(ide_drive_t *ide_drive) |
| 141 | { |
| 142 | return scsihost_to_idescsi(ide_drive->driver_data); |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * Per ATAPI device status bits. |
| 147 | */ |
| 148 | #define IDESCSI_DRQ_INTERRUPT 0 /* DRQ interrupt device */ |
| 149 | |
| 150 | /* |
| 151 | * ide-scsi requests. |
| 152 | */ |
| 153 | #define IDESCSI_PC_RQ 90 |
| 154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | /* |
| 156 | * PIO data transfer routines using the scatter gather table. |
| 157 | */ |
| 158 | static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) |
| 159 | { |
| 160 | int count; |
| 161 | char *buf; |
| 162 | |
| 163 | while (bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | count = min(pc->sg->length - pc->b_count, bcount); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 165 | if (PageHighMem(sg_page(pc->sg))) { |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 166 | unsigned long flags; |
| 167 | |
| 168 | local_irq_save(flags); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 169 | buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) + |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 170 | pc->sg->offset; |
| 171 | drive->hwif->atapi_input_bytes(drive, |
| 172 | buf + pc->b_count, count); |
| 173 | kunmap_atomic(buf - pc->sg->offset, KM_IRQ0); |
| 174 | local_irq_restore(flags); |
| 175 | } else { |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 176 | buf = sg_virt(pc->sg); |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 177 | drive->hwif->atapi_input_bytes(drive, |
| 178 | buf + pc->b_count, count); |
| 179 | } |
| 180 | bcount -= count; pc->b_count += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (pc->b_count == pc->sg->length) { |
Jens Axboe | c79d88b | 2007-10-17 13:16:35 +0200 | [diff] [blame] | 182 | if (!--pc->sg_cnt) |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 183 | break; |
| 184 | pc->sg = sg_next(pc->sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | pc->b_count = 0; |
| 186 | } |
| 187 | } |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 188 | |
| 189 | if (bcount) { |
| 190 | printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n"); |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 191 | ide_atapi_discard_data(drive, bcount); |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) |
| 196 | { |
| 197 | int count; |
| 198 | char *buf; |
| 199 | |
| 200 | while (bcount) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | count = min(pc->sg->length - pc->b_count, bcount); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 202 | if (PageHighMem(sg_page(pc->sg))) { |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 203 | unsigned long flags; |
| 204 | |
| 205 | local_irq_save(flags); |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 206 | buf = kmap_atomic(sg_page(pc->sg), KM_IRQ0) + |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 207 | pc->sg->offset; |
| 208 | drive->hwif->atapi_output_bytes(drive, |
| 209 | buf + pc->b_count, count); |
| 210 | kunmap_atomic(buf - pc->sg->offset, KM_IRQ0); |
| 211 | local_irq_restore(flags); |
| 212 | } else { |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 213 | buf = sg_virt(pc->sg); |
Andrew Morton | a717f77 | 2005-10-31 14:08:53 -0800 | [diff] [blame] | 214 | drive->hwif->atapi_output_bytes(drive, |
| 215 | buf + pc->b_count, count); |
| 216 | } |
| 217 | bcount -= count; pc->b_count += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (pc->b_count == pc->sg->length) { |
Jens Axboe | c79d88b | 2007-10-17 13:16:35 +0200 | [diff] [blame] | 219 | if (!--pc->sg_cnt) |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 220 | break; |
| 221 | pc->sg = sg_next(pc->sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | pc->b_count = 0; |
| 223 | } |
| 224 | } |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 225 | |
| 226 | if (bcount) { |
| 227 | printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n"); |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 228 | ide_atapi_write_zeros(drive, bcount); |
Jens Axboe | d274a98 | 2007-10-16 11:20:52 +0200 | [diff] [blame] | 229 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | |
Bartlomiej Zolnierkiewicz | 69ae6fe | 2007-12-12 23:31:57 +0100 | [diff] [blame] | 232 | static void ide_scsi_hex_dump(u8 *data, int len) |
| 233 | { |
| 234 | print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0); |
| 235 | } |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command) |
| 238 | { |
| 239 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
| 240 | idescsi_pc_t *pc; |
| 241 | struct request *rq; |
| 242 | u8 *buf; |
| 243 | |
| 244 | /* stuff a sense request in front of our current request */ |
Mariusz Kozlowski | 41ead3c | 2007-08-01 23:46:45 +0200 | [diff] [blame] | 245 | pc = kzalloc(sizeof(idescsi_pc_t), GFP_ATOMIC); |
| 246 | rq = kmalloc(sizeof(struct request), GFP_ATOMIC); |
| 247 | buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC); |
| 248 | if (!pc || !rq || !buf) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 249 | kfree(buf); |
| 250 | kfree(rq); |
| 251 | kfree(pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | return -ENOMEM; |
| 253 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | ide_init_drive_cmd(rq); |
| 255 | rq->special = (char *) pc; |
| 256 | pc->rq = rq; |
| 257 | pc->buffer = buf; |
| 258 | pc->c[0] = REQUEST_SENSE; |
| 259 | pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 260 | rq->cmd_type = REQ_TYPE_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | pc->timeout = jiffies + WAIT_READY; |
| 262 | /* NOTE! Save the failed packet command in "rq->buffer" */ |
| 263 | rq->buffer = (void *) failed_command->special; |
| 264 | pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd; |
| 265 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { |
| 266 | printk ("ide-scsi: %s: queue cmd = ", drive->name); |
Bartlomiej Zolnierkiewicz | 69ae6fe | 2007-12-12 23:31:57 +0100 | [diff] [blame] | 267 | ide_scsi_hex_dump(pc->c, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | rq->rq_disk = scsi->disk; |
| 270 | return ide_do_drive_cmd(drive, rq, ide_preempt); |
| 271 | } |
| 272 | |
| 273 | static int idescsi_end_request(ide_drive_t *, int, int); |
| 274 | |
| 275 | static ide_startstop_t |
| 276 | idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) |
| 277 | { |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame^] | 278 | ide_hwif_t *hwif = drive->hwif; |
| 279 | |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 280 | if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* force an abort */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame^] | 282 | hwif->OUTB(WIN_IDLEIMMEDIATE, |
| 283 | hwif->io_ports[IDE_COMMAND_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
| 285 | rq->errors++; |
| 286 | |
| 287 | idescsi_end_request(drive, 0, 0); |
| 288 | |
| 289 | return ide_stopped; |
| 290 | } |
| 291 | |
| 292 | static ide_startstop_t |
| 293 | idescsi_atapi_abort(ide_drive_t *drive, struct request *rq) |
| 294 | { |
| 295 | #if IDESCSI_DEBUG_LOG |
| 296 | printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n", |
| 297 | ((idescsi_pc_t *) rq->special)->scsi_cmd->serial_number); |
| 298 | #endif |
| 299 | rq->errors |= ERROR_MAX; |
| 300 | |
| 301 | idescsi_end_request(drive, 0, 0); |
| 302 | |
| 303 | return ide_stopped; |
| 304 | } |
| 305 | |
| 306 | static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs) |
| 307 | { |
| 308 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
| 309 | struct request *rq = HWGROUP(drive)->rq; |
| 310 | idescsi_pc_t *pc = (idescsi_pc_t *) rq->special; |
| 311 | int log = test_bit(IDESCSI_LOG_CMD, &scsi->log); |
| 312 | struct Scsi_Host *host; |
Willem Riede | 3256534 | 2005-10-31 00:03:49 +0000 | [diff] [blame] | 313 | int errors = rq->errors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | unsigned long flags; |
| 315 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 316 | if (!blk_special_request(rq) && !blk_sense_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | ide_end_request(drive, uptodate, nrsecs); |
| 318 | return 0; |
| 319 | } |
| 320 | ide_end_drive_cmd (drive, 0, 0); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 321 | if (blk_sense_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer; |
| 323 | if (log) { |
| 324 | printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number); |
Bartlomiej Zolnierkiewicz | 69ae6fe | 2007-12-12 23:31:57 +0100 | [diff] [blame] | 325 | ide_scsi_hex_dump(pc->buffer, 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE); |
| 328 | kfree(pc->buffer); |
| 329 | kfree(pc); |
| 330 | kfree(rq); |
| 331 | pc = opc; |
| 332 | rq = pc->rq; |
| 333 | pc->scsi_cmd->result = (CHECK_CONDITION << 1) | |
| 334 | ((test_bit(PC_TIMEDOUT, &pc->flags)?DID_TIME_OUT:DID_OK) << 16); |
| 335 | } else if (test_bit(PC_TIMEDOUT, &pc->flags)) { |
| 336 | if (log) |
| 337 | printk (KERN_WARNING "ide-scsi: %s: timed out for %lu\n", |
| 338 | drive->name, pc->scsi_cmd->serial_number); |
| 339 | pc->scsi_cmd->result = DID_TIME_OUT << 16; |
Willem Riede | 3256534 | 2005-10-31 00:03:49 +0000 | [diff] [blame] | 340 | } else if (errors >= ERROR_MAX) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | pc->scsi_cmd->result = DID_ERROR << 16; |
| 342 | if (log) |
| 343 | printk ("ide-scsi: %s: I/O error for %lu\n", drive->name, pc->scsi_cmd->serial_number); |
Willem Riede | 3256534 | 2005-10-31 00:03:49 +0000 | [diff] [blame] | 344 | } else if (errors) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | if (log) |
| 346 | printk ("ide-scsi: %s: check condition for %lu\n", drive->name, pc->scsi_cmd->serial_number); |
| 347 | if (!idescsi_check_condition(drive, rq)) |
| 348 | /* we started a request sense, so we'll be back, exit for now */ |
| 349 | return 0; |
| 350 | pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16); |
| 351 | } else { |
| 352 | pc->scsi_cmd->result = DID_OK << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | } |
| 354 | host = pc->scsi_cmd->device->host; |
| 355 | spin_lock_irqsave(host->host_lock, flags); |
| 356 | pc->done(pc->scsi_cmd); |
| 357 | spin_unlock_irqrestore(host->host_lock, flags); |
| 358 | kfree(pc); |
| 359 | kfree(rq); |
| 360 | scsi->pc = NULL; |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static inline unsigned long get_timeout(idescsi_pc_t *pc) |
| 365 | { |
| 366 | return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies); |
| 367 | } |
| 368 | |
| 369 | static int idescsi_expiry(ide_drive_t *drive) |
| 370 | { |
Bartlomiej Zolnierkiewicz | d1be0a8 | 2007-06-16 02:24:44 +0200 | [diff] [blame] | 371 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | idescsi_pc_t *pc = scsi->pc; |
| 373 | |
| 374 | #if IDESCSI_DEBUG_LOG |
| 375 | printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies); |
| 376 | #endif |
| 377 | set_bit(PC_TIMEDOUT, &pc->flags); |
| 378 | |
| 379 | return 0; /* we do not want the ide subsystem to retry */ |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Our interrupt handler. |
| 384 | */ |
| 385 | static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive) |
| 386 | { |
| 387 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 388 | ide_hwif_t *hwif = drive->hwif; |
| 389 | idescsi_pc_t *pc = scsi->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | struct request *rq = pc->rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | unsigned int temp; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 392 | u16 bcount; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 393 | u8 stat, ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | #if IDESCSI_DEBUG_LOG |
| 396 | printk (KERN_INFO "ide-scsi: Reached idescsi_pc_intr interrupt handler\n"); |
| 397 | #endif /* IDESCSI_DEBUG_LOG */ |
| 398 | |
| 399 | if (test_bit(PC_TIMEDOUT, &pc->flags)){ |
| 400 | #if IDESCSI_DEBUG_LOG |
| 401 | printk(KERN_WARNING "idescsi_pc_intr: got timed out packet %lu at %lu\n", |
| 402 | pc->scsi_cmd->serial_number, jiffies); |
| 403 | #endif |
| 404 | /* end this request now - scsi should retry it*/ |
| 405 | idescsi_end_request (drive, 1, 0); |
| 406 | return ide_stopped; |
| 407 | } |
| 408 | if (test_and_clear_bit (PC_DMA_IN_PROGRESS, &pc->flags)) { |
| 409 | #if IDESCSI_DEBUG_LOG |
| 410 | printk ("ide-scsi: %s: DMA complete\n", drive->name); |
| 411 | #endif /* IDESCSI_DEBUG_LOG */ |
| 412 | pc->actually_transferred=pc->request_transfer; |
| 413 | (void) HWIF(drive)->ide_dma_end(drive); |
| 414 | } |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | /* Clear the interrupt */ |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 417 | stat = ide_read_status(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 419 | if ((stat & DRQ_STAT) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | /* No more interrupts */ |
| 421 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) |
| 422 | printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred); |
Ingo Molnar | 36e8e57 | 2006-08-27 01:23:56 -0700 | [diff] [blame] | 423 | local_irq_enable_in_hardirq(); |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 424 | if (stat & ERR_STAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | rq->errors++; |
| 426 | idescsi_end_request (drive, 1, 0); |
| 427 | return ide_stopped; |
| 428 | } |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame^] | 429 | bcount = (hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]) << 8) | |
| 430 | hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); |
| 431 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 433 | if (ireason & CD) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | printk(KERN_ERR "ide-scsi: CoD != 0 in idescsi_pc_intr\n"); |
| 435 | return ide_do_reset (drive); |
| 436 | } |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 437 | if (ireason & IO) { |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 438 | temp = pc->actually_transferred + bcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | if (temp > pc->request_transfer) { |
| 440 | if (temp > pc->buffer_size) { |
| 441 | printk(KERN_ERR "ide-scsi: The scsi wants to " |
| 442 | "send us more data than expected " |
| 443 | "- discarding data\n"); |
| 444 | temp = pc->buffer_size - pc->actually_transferred; |
| 445 | if (temp) { |
| 446 | clear_bit(PC_WRITING, &pc->flags); |
| 447 | if (pc->sg) |
| 448 | idescsi_input_buffers(drive, pc, temp); |
| 449 | else |
| 450 | drive->hwif->atapi_input_bytes(drive, pc->current_position, temp); |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 451 | printk(KERN_ERR "ide-scsi: transferred" |
| 452 | " %d of %d bytes\n", |
| 453 | temp, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | pc->actually_transferred += temp; |
| 456 | pc->current_position += temp; |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 457 | ide_atapi_discard_data(drive, bcount - temp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); |
| 459 | return ide_started; |
| 460 | } |
| 461 | #if IDESCSI_DEBUG_LOG |
| 462 | printk (KERN_NOTICE "ide-scsi: The scsi wants to send us more data than expected - allowing transfer\n"); |
| 463 | #endif /* IDESCSI_DEBUG_LOG */ |
| 464 | } |
| 465 | } |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 466 | if (ireason & IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | clear_bit(PC_WRITING, &pc->flags); |
| 468 | if (pc->sg) |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 469 | idescsi_input_buffers(drive, pc, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | else |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 471 | hwif->atapi_input_bytes(drive, pc->current_position, |
| 472 | bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } else { |
| 474 | set_bit(PC_WRITING, &pc->flags); |
| 475 | if (pc->sg) |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 476 | idescsi_output_buffers(drive, pc, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | else |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 478 | hwif->atapi_output_bytes(drive, pc->current_position, |
| 479 | bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | /* Update the current position */ |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 482 | pc->actually_transferred += bcount; |
| 483 | pc->current_position += bcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | /* And set the interrupt handler again */ |
| 486 | ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); |
| 487 | return ide_started; |
| 488 | } |
| 489 | |
| 490 | static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive) |
| 491 | { |
| 492 | ide_hwif_t *hwif = drive->hwif; |
| 493 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
| 494 | idescsi_pc_t *pc = scsi->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | ide_startstop_t startstop; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 496 | u8 ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | |
| 498 | if (ide_wait_stat(&startstop,drive,DRQ_STAT,BUSY_STAT,WAIT_READY)) { |
| 499 | printk(KERN_ERR "ide-scsi: Strange, packet command " |
| 500 | "initiated yet DRQ isn't asserted\n"); |
| 501 | return startstop; |
| 502 | } |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame^] | 503 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 504 | if ((ireason & CD) == 0 || (ireason & IO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | printk(KERN_ERR "ide-scsi: (IO,CoD) != (0,1) while " |
| 506 | "issuing a packet command\n"); |
| 507 | return ide_do_reset (drive); |
| 508 | } |
Eric Sesterhenn | 125e187 | 2006-06-23 02:06:06 -0700 | [diff] [blame] | 509 | BUG_ON(HWGROUP(drive)->handler != NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* Set the interrupt routine */ |
| 511 | ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); |
| 512 | /* Send the actual packet */ |
| 513 | drive->hwif->atapi_output_bytes(drive, scsi->pc->c, 12); |
| 514 | if (test_bit (PC_DMA_OK, &pc->flags)) { |
| 515 | set_bit (PC_DMA_IN_PROGRESS, &pc->flags); |
| 516 | hwif->dma_start(drive); |
| 517 | } |
| 518 | return ide_started; |
| 519 | } |
| 520 | |
| 521 | static inline int idescsi_set_direction(idescsi_pc_t *pc) |
| 522 | { |
| 523 | switch (pc->c[0]) { |
| 524 | case READ_6: case READ_10: case READ_12: |
| 525 | clear_bit(PC_WRITING, &pc->flags); |
| 526 | return 0; |
| 527 | case WRITE_6: case WRITE_10: case WRITE_12: |
| 528 | set_bit(PC_WRITING, &pc->flags); |
| 529 | return 0; |
| 530 | default: |
| 531 | return 1; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc) |
| 536 | { |
| 537 | ide_hwif_t *hwif = drive->hwif; |
| 538 | struct scatterlist *sg, *scsi_sg; |
| 539 | int segments; |
| 540 | |
| 541 | if (!pc->request_transfer || pc->request_transfer % 1024) |
| 542 | return 1; |
| 543 | |
| 544 | if (idescsi_set_direction(pc)) |
| 545 | return 1; |
| 546 | |
| 547 | sg = hwif->sg_table; |
Boaz Harrosh | 427d0bd | 2007-09-18 12:27:43 +0200 | [diff] [blame] | 548 | scsi_sg = scsi_sglist(pc->scsi_cmd); |
| 549 | segments = scsi_sg_count(pc->scsi_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | if (segments > hwif->sg_max_nents) |
| 552 | return 1; |
| 553 | |
Boaz Harrosh | 427d0bd | 2007-09-18 12:27:43 +0200 | [diff] [blame] | 554 | hwif->sg_nents = segments; |
| 555 | memcpy(sg, scsi_sg, sizeof(*sg) * segments); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | * Issue a packet command |
| 562 | */ |
| 563 | static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc) |
| 564 | { |
| 565 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
| 566 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 567 | u16 bcount; |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 568 | u8 dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | scsi->pc=pc; /* Set the current packet command */ |
| 571 | pc->actually_transferred=0; /* We haven't transferred any data yet */ |
| 572 | pc->current_position=pc->buffer; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 573 | /* Request to transfer the entire buffer at once */ |
| 574 | bcount = min(pc->request_transfer, 63 * 1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | if (drive->using_dma && !idescsi_map_sg(drive, pc)) { |
| 577 | hwif->sg_mapped = 1; |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 578 | dma = !hwif->dma_setup(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | hwif->sg_mapped = 0; |
| 580 | } |
| 581 | |
Bartlomiej Zolnierkiewicz | 2fc5738 | 2008-01-25 22:17:13 +0100 | [diff] [blame] | 582 | ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK, bcount, dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 584 | if (dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | set_bit(PC_DMA_OK, &pc->flags); |
| 586 | |
| 587 | if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) { |
Bartlomiej Zolnierkiewicz | 2d6027f | 2008-02-02 19:56:44 +0100 | [diff] [blame] | 588 | ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc, |
| 589 | get_timeout(pc), idescsi_expiry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return ide_started; |
| 591 | } else { |
| 592 | /* Issue the packet command */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame^] | 593 | hwif->OUTB(WIN_PACKETCMD, hwif->io_ports[IDE_COMMAND_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return idescsi_transfer_pc(drive); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | /* |
| 599 | * idescsi_do_request is our request handling function. |
| 600 | */ |
| 601 | static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *rq, sector_t block) |
| 602 | { |
| 603 | #if IDESCSI_DEBUG_LOG |
Jens Axboe | cdd6026 | 2006-07-28 09:32:07 +0200 | [diff] [blame] | 604 | printk (KERN_INFO "dev: %s, cmd: %x, errors: %d\n", rq->rq_disk->disk_name,rq->cmd[0],rq->errors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | printk (KERN_INFO "sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",rq->sector,rq->nr_sectors,rq->current_nr_sectors); |
| 606 | #endif /* IDESCSI_DEBUG_LOG */ |
| 607 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 608 | if (blk_sense_request(rq) || blk_special_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special); |
| 610 | } |
| 611 | blk_dump_rq_flags(rq, "ide-scsi: unsup command"); |
| 612 | idescsi_end_request (drive, 0, 0); |
| 613 | return ide_stopped; |
| 614 | } |
| 615 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 616 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | static void idescsi_add_settings(ide_drive_t *drive) |
| 618 | { |
| 619 | idescsi_scsi_t *scsi = drive_to_idescsi(drive); |
| 620 | |
| 621 | /* |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 622 | * drive setting name read/write data type min max mul_factor div_factor data pointer set function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | */ |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 624 | ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL); |
| 625 | ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); |
| 626 | ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); |
| 627 | ide_add_setting(drive, "transform", SETTING_RW, TYPE_INT, 0, 3, 1, 1, &scsi->transform, NULL); |
| 628 | ide_add_setting(drive, "log", SETTING_RW, TYPE_INT, 0, 1, 1, 1, &scsi->log, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | } |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 630 | #else |
| 631 | static inline void idescsi_add_settings(ide_drive_t *drive) { ; } |
| 632 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | /* |
| 635 | * Driver initialization. |
| 636 | */ |
| 637 | static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi) |
| 638 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | if (drive->id && (drive->id->config & 0x0060) == 0x20) |
| 640 | set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform); |
| 642 | #if IDESCSI_DEBUG_LOG |
| 643 | set_bit(IDESCSI_LOG_CMD, &scsi->log); |
| 644 | #endif /* IDESCSI_DEBUG_LOG */ |
| 645 | idescsi_add_settings(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
Mikael Pettersson | b62735d | 2006-02-01 03:04:45 -0800 | [diff] [blame] | 648 | static void ide_scsi_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
| 650 | struct Scsi_Host *scsihost = drive->driver_data; |
| 651 | struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost); |
| 652 | struct gendisk *g = scsi->disk; |
| 653 | |
Matthew Wilcox | 6fdea8d | 2007-08-15 12:57:01 -0600 | [diff] [blame] | 654 | scsi_remove_host(scsihost); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 655 | ide_proc_unregister_driver(drive, scsi->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
| 657 | ide_unregister_region(g); |
| 658 | |
| 659 | drive->driver_data = NULL; |
| 660 | g->private_data = NULL; |
| 661 | put_disk(g); |
| 662 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | ide_scsi_put(scsi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Mikael Pettersson | b62735d | 2006-02-01 03:04:45 -0800 | [diff] [blame] | 666 | static int ide_scsi_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 668 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | static ide_proc_entry_t idescsi_proc[] = { |
| 670 | { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, |
| 671 | { NULL, 0, NULL, NULL } |
| 672 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | #endif |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | static ide_driver_t idescsi_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 676 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 677 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 678 | .name = "ide-scsi", |
| 679 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 680 | }, |
Mikael Pettersson | b62735d | 2006-02-01 03:04:45 -0800 | [diff] [blame] | 681 | .probe = ide_scsi_probe, |
| 682 | .remove = ide_scsi_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | .version = IDESCSI_VERSION, |
| 684 | .media = ide_scsi, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | .supports_dsc_overlap = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | .do_request = idescsi_do_request, |
| 687 | .end_request = idescsi_end_request, |
| 688 | .error = idescsi_atapi_error, |
| 689 | .abort = idescsi_atapi_abort, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 690 | #ifdef CONFIG_IDE_PROC_FS |
| 691 | .proc = idescsi_proc, |
| 692 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | }; |
| 694 | |
| 695 | static int idescsi_ide_open(struct inode *inode, struct file *filp) |
| 696 | { |
| 697 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 698 | struct ide_scsi_obj *scsi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | if (!(scsi = ide_scsi_get(disk))) |
| 701 | return -ENXIO; |
| 702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
| 706 | static int idescsi_ide_release(struct inode *inode, struct file *filp) |
| 707 | { |
| 708 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 709 | struct ide_scsi_obj *scsi = ide_scsi_g(disk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
| 711 | ide_scsi_put(scsi); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static int idescsi_ide_ioctl(struct inode *inode, struct file *file, |
| 717 | unsigned int cmd, unsigned long arg) |
| 718 | { |
| 719 | struct block_device *bdev = inode->i_bdev; |
| 720 | struct ide_scsi_obj *scsi = ide_scsi_g(bdev->bd_disk); |
| 721 | return generic_ide_ioctl(scsi->drive, file, bdev, cmd, arg); |
| 722 | } |
| 723 | |
| 724 | static struct block_device_operations idescsi_ops = { |
| 725 | .owner = THIS_MODULE, |
| 726 | .open = idescsi_ide_open, |
| 727 | .release = idescsi_ide_release, |
| 728 | .ioctl = idescsi_ide_ioctl, |
| 729 | }; |
| 730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | static int idescsi_slave_configure(struct scsi_device * sdp) |
| 732 | { |
| 733 | /* Configure detected device */ |
Boaz Harrosh | 427d0bd | 2007-09-18 12:27:43 +0200 | [diff] [blame] | 734 | sdp->use_10_for_rw = 1; |
| 735 | sdp->use_10_for_ms = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun); |
| 737 | return 0; |
| 738 | } |
| 739 | |
| 740 | static const char *idescsi_info (struct Scsi_Host *host) |
| 741 | { |
| 742 | return "SCSI host adapter emulation for IDE ATAPI devices"; |
| 743 | } |
| 744 | |
| 745 | static int idescsi_ioctl (struct scsi_device *dev, int cmd, void __user *arg) |
| 746 | { |
| 747 | idescsi_scsi_t *scsi = scsihost_to_idescsi(dev->host); |
| 748 | |
| 749 | if (cmd == SG_SET_TRANSFORM) { |
| 750 | if (arg) |
| 751 | set_bit(IDESCSI_SG_TRANSFORM, &scsi->transform); |
| 752 | else |
| 753 | clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform); |
| 754 | return 0; |
| 755 | } else if (cmd == SG_GET_TRANSFORM) |
| 756 | return put_user(test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform), (int __user *) arg); |
| 757 | return -EINVAL; |
| 758 | } |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | static int idescsi_queue (struct scsi_cmnd *cmd, |
| 761 | void (*done)(struct scsi_cmnd *)) |
| 762 | { |
| 763 | struct Scsi_Host *host = cmd->device->host; |
| 764 | idescsi_scsi_t *scsi = scsihost_to_idescsi(host); |
| 765 | ide_drive_t *drive = scsi->drive; |
| 766 | struct request *rq = NULL; |
| 767 | idescsi_pc_t *pc = NULL; |
| 768 | |
| 769 | if (!drive) { |
Jeff Garzik | 017560f | 2005-10-24 18:04:36 -0400 | [diff] [blame] | 770 | scmd_printk (KERN_ERR, cmd, "drive not present\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | goto abort; |
| 772 | } |
| 773 | scsi = drive_to_idescsi(drive); |
| 774 | pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC); |
| 775 | rq = kmalloc (sizeof (struct request), GFP_ATOMIC); |
| 776 | if (rq == NULL || pc == NULL) { |
| 777 | printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name); |
| 778 | goto abort; |
| 779 | } |
| 780 | |
| 781 | memset (pc->c, 0, 12); |
| 782 | pc->flags = 0; |
| 783 | pc->rq = rq; |
| 784 | memcpy (pc->c, cmd->cmnd, cmd->cmd_len); |
Boaz Harrosh | 427d0bd | 2007-09-18 12:27:43 +0200 | [diff] [blame] | 785 | pc->buffer = NULL; |
| 786 | pc->sg = scsi_sglist(cmd); |
Jens Axboe | c79d88b | 2007-10-17 13:16:35 +0200 | [diff] [blame] | 787 | pc->sg_cnt = scsi_sg_count(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | pc->b_count = 0; |
Boaz Harrosh | 427d0bd | 2007-09-18 12:27:43 +0200 | [diff] [blame] | 789 | pc->request_transfer = pc->buffer_size = scsi_bufflen(cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | pc->scsi_cmd = cmd; |
| 791 | pc->done = done; |
| 792 | pc->timeout = jiffies + cmd->timeout_per_command; |
| 793 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { |
| 795 | printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number); |
Bartlomiej Zolnierkiewicz | 69ae6fe | 2007-12-12 23:31:57 +0100 | [diff] [blame] | 796 | ide_scsi_hex_dump(cmd->cmnd, cmd->cmd_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | if (memcmp(pc->c, cmd->cmnd, cmd->cmd_len)) { |
| 798 | printk ("ide-scsi: %s: que %lu, tsl = ", drive->name, cmd->serial_number); |
Bartlomiej Zolnierkiewicz | 69ae6fe | 2007-12-12 23:31:57 +0100 | [diff] [blame] | 799 | ide_scsi_hex_dump(pc->c, 12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
| 803 | ide_init_drive_cmd (rq); |
| 804 | rq->special = (char *) pc; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 805 | rq->cmd_type = REQ_TYPE_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | spin_unlock_irq(host->host_lock); |
| 807 | rq->rq_disk = scsi->disk; |
| 808 | (void) ide_do_drive_cmd (drive, rq, ide_end); |
| 809 | spin_lock_irq(host->host_lock); |
| 810 | return 0; |
| 811 | abort: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 812 | kfree (pc); |
| 813 | kfree (rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | cmd->result = DID_ERROR << 16; |
| 815 | done(cmd); |
| 816 | return 0; |
| 817 | } |
| 818 | |
| 819 | static int idescsi_eh_abort (struct scsi_cmnd *cmd) |
| 820 | { |
| 821 | idescsi_scsi_t *scsi = scsihost_to_idescsi(cmd->device->host); |
| 822 | ide_drive_t *drive = scsi->drive; |
| 823 | int busy; |
| 824 | int ret = FAILED; |
| 825 | |
| 826 | /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */ |
| 827 | |
| 828 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) |
| 829 | printk (KERN_WARNING "ide-scsi: abort called for %lu\n", cmd->serial_number); |
| 830 | |
| 831 | if (!drive) { |
| 832 | printk (KERN_WARNING "ide-scsi: Drive not set in idescsi_eh_abort\n"); |
| 833 | WARN_ON(1); |
| 834 | goto no_drive; |
| 835 | } |
| 836 | |
| 837 | /* First give it some more time, how much is "right" is hard to say :-( */ |
| 838 | |
| 839 | busy = ide_wait_not_busy(HWIF(drive), 100); /* FIXME - uses mdelay which causes latency? */ |
| 840 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) |
| 841 | printk (KERN_WARNING "ide-scsi: drive did%s become ready\n", busy?" not":""); |
| 842 | |
| 843 | spin_lock_irq(&ide_lock); |
| 844 | |
| 845 | /* If there is no pc running we're done (our interrupt took care of it) */ |
| 846 | if (!scsi->pc) { |
| 847 | ret = SUCCESS; |
| 848 | goto ide_unlock; |
| 849 | } |
| 850 | |
| 851 | /* It's somewhere in flight. Does ide subsystem agree? */ |
| 852 | if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy && |
| 853 | elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) { |
| 854 | /* |
| 855 | * FIXME - not sure this condition can ever occur |
| 856 | */ |
| 857 | printk (KERN_ERR "ide-scsi: cmd aborted!\n"); |
| 858 | |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 859 | if (blk_sense_request(scsi->pc->rq)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | kfree(scsi->pc->buffer); |
| 861 | kfree(scsi->pc->rq); |
| 862 | kfree(scsi->pc); |
| 863 | scsi->pc = NULL; |
| 864 | |
| 865 | ret = SUCCESS; |
| 866 | } |
| 867 | |
| 868 | ide_unlock: |
| 869 | spin_unlock_irq(&ide_lock); |
| 870 | no_drive: |
| 871 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) |
| 872 | printk (KERN_WARNING "ide-scsi: abort returns %s\n", ret == SUCCESS?"success":"failed"); |
| 873 | |
| 874 | return ret; |
| 875 | } |
| 876 | |
| 877 | static int idescsi_eh_reset (struct scsi_cmnd *cmd) |
| 878 | { |
| 879 | struct request *req; |
| 880 | idescsi_scsi_t *scsi = scsihost_to_idescsi(cmd->device->host); |
| 881 | ide_drive_t *drive = scsi->drive; |
| 882 | int ready = 0; |
| 883 | int ret = SUCCESS; |
| 884 | |
| 885 | /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */ |
| 886 | |
| 887 | if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) |
| 888 | printk (KERN_WARNING "ide-scsi: reset called for %lu\n", cmd->serial_number); |
| 889 | |
| 890 | if (!drive) { |
| 891 | printk (KERN_WARNING "ide-scsi: Drive not set in idescsi_eh_reset\n"); |
| 892 | WARN_ON(1); |
| 893 | return FAILED; |
| 894 | } |
| 895 | |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 896 | spin_lock_irq(cmd->device->host->host_lock); |
| 897 | spin_lock(&ide_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
| 899 | if (!scsi->pc || (req = scsi->pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) { |
| 900 | printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n"); |
| 901 | spin_unlock(&ide_lock); |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 902 | spin_unlock_irq(cmd->device->host->host_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | return FAILED; |
| 904 | } |
| 905 | |
| 906 | /* kill current request */ |
Kiyoshi Ueda | 5a330e3 | 2007-12-11 17:49:29 -0500 | [diff] [blame] | 907 | if (__blk_end_request(req, -EIO, 0)) |
| 908 | BUG(); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 909 | if (blk_sense_request(req)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | kfree(scsi->pc->buffer); |
| 911 | kfree(scsi->pc); |
| 912 | scsi->pc = NULL; |
| 913 | kfree(req); |
| 914 | |
| 915 | /* now nuke the drive queue */ |
| 916 | while ((req = elv_next_request(drive->queue))) { |
Kiyoshi Ueda | 5a330e3 | 2007-12-11 17:49:29 -0500 | [diff] [blame] | 917 | if (__blk_end_request(req, -EIO, 0)) |
| 918 | BUG(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | HWGROUP(drive)->rq = NULL; |
| 922 | HWGROUP(drive)->handler = NULL; |
| 923 | HWGROUP(drive)->busy = 1; /* will set this to zero when ide reset finished */ |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 924 | spin_unlock(&ide_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | ide_do_reset(drive); |
| 927 | |
| 928 | /* ide_do_reset starts a polling handler which restarts itself every 50ms until the reset finishes */ |
| 929 | |
| 930 | do { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | spin_unlock_irq(cmd->device->host->host_lock); |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 932 | msleep(50); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | spin_lock_irq(cmd->device->host->host_lock); |
| 934 | } while ( HWGROUP(drive)->handler ); |
| 935 | |
| 936 | ready = drive_is_ready(drive); |
| 937 | HWGROUP(drive)->busy--; |
| 938 | if (!ready) { |
| 939 | printk (KERN_ERR "ide-scsi: reset failed!\n"); |
| 940 | ret = FAILED; |
| 941 | } |
| 942 | |
Jeff Garzik | df0ae24 | 2005-05-28 07:57:14 -0400 | [diff] [blame] | 943 | spin_unlock_irq(cmd->device->host->host_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | |
| 947 | static int idescsi_bios(struct scsi_device *sdev, struct block_device *bdev, |
| 948 | sector_t capacity, int *parm) |
| 949 | { |
| 950 | idescsi_scsi_t *idescsi = scsihost_to_idescsi(sdev->host); |
| 951 | ide_drive_t *drive = idescsi->drive; |
| 952 | |
| 953 | if (drive->bios_cyl && drive->bios_head && drive->bios_sect) { |
| 954 | parm[0] = drive->bios_head; |
| 955 | parm[1] = drive->bios_sect; |
| 956 | parm[2] = drive->bios_cyl; |
| 957 | } |
| 958 | return 0; |
| 959 | } |
| 960 | |
| 961 | static struct scsi_host_template idescsi_template = { |
| 962 | .module = THIS_MODULE, |
| 963 | .name = "idescsi", |
| 964 | .info = idescsi_info, |
| 965 | .slave_configure = idescsi_slave_configure, |
| 966 | .ioctl = idescsi_ioctl, |
| 967 | .queuecommand = idescsi_queue, |
| 968 | .eh_abort_handler = idescsi_eh_abort, |
| 969 | .eh_host_reset_handler = idescsi_eh_reset, |
| 970 | .bios_param = idescsi_bios, |
| 971 | .can_queue = 40, |
| 972 | .this_id = -1, |
| 973 | .sg_tablesize = 256, |
| 974 | .cmd_per_lun = 5, |
| 975 | .max_sectors = 128, |
| 976 | .use_clustering = DISABLE_CLUSTERING, |
| 977 | .emulated = 1, |
| 978 | .proc_name = "ide-scsi", |
| 979 | }; |
| 980 | |
Mikael Pettersson | b62735d | 2006-02-01 03:04:45 -0800 | [diff] [blame] | 981 | static int ide_scsi_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | { |
| 983 | idescsi_scsi_t *idescsi; |
| 984 | struct Scsi_Host *host; |
| 985 | struct gendisk *g; |
| 986 | static int warned; |
| 987 | int err = -ENOMEM; |
| 988 | |
| 989 | if (!warned && drive->media == ide_cdrom) { |
| 990 | printk(KERN_WARNING "ide-scsi is deprecated for cd burning! Use ide-cd and give dev=/dev/hdX as device\n"); |
| 991 | warned = 1; |
| 992 | } |
| 993 | |
Alan Cox | aaeab80 | 2006-12-06 20:39:33 -0800 | [diff] [blame] | 994 | if (idescsi_nocd && drive->media == ide_cdrom) |
| 995 | return -ENODEV; |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (!strstr("ide-scsi", drive->driver_req) || |
| 998 | !drive->present || |
| 999 | drive->media == ide_disk || |
| 1000 | !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t)))) |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1001 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | g = alloc_disk(1 << PARTN_BITS); |
| 1004 | if (!g) |
| 1005 | goto out_host_put; |
| 1006 | |
| 1007 | ide_init_disk(g, drive); |
| 1008 | |
| 1009 | host->max_id = 1; |
| 1010 | |
| 1011 | #if IDESCSI_DEBUG_LOG |
| 1012 | if (drive->id->last_lun) |
| 1013 | printk(KERN_NOTICE "%s: id->last_lun=%u\n", drive->name, drive->id->last_lun); |
| 1014 | #endif |
| 1015 | if ((drive->id->last_lun & 0x7) != 7) |
| 1016 | host->max_lun = (drive->id->last_lun & 0x7) + 1; |
| 1017 | else |
| 1018 | host->max_lun = 1; |
| 1019 | |
| 1020 | drive->driver_data = host; |
| 1021 | idescsi = scsihost_to_idescsi(host); |
| 1022 | idescsi->drive = drive; |
| 1023 | idescsi->driver = &idescsi_driver; |
| 1024 | idescsi->host = host; |
| 1025 | idescsi->disk = g; |
| 1026 | g->private_data = &idescsi->driver; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1027 | ide_proc_register_driver(drive, &idescsi_driver); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1028 | err = 0; |
| 1029 | idescsi_setup(drive, idescsi); |
| 1030 | g->fops = &idescsi_ops; |
| 1031 | ide_register_region(g); |
| 1032 | err = scsi_add_host(host, &drive->gendev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | if (!err) { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1034 | scsi_scan_host(host); |
| 1035 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | } |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1037 | /* fall through on error */ |
| 1038 | ide_unregister_region(g); |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1039 | ide_proc_unregister_driver(drive, &idescsi_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | |
| 1041 | put_disk(g); |
| 1042 | out_host_put: |
| 1043 | scsi_host_put(host); |
| 1044 | return err; |
| 1045 | } |
| 1046 | |
| 1047 | static int __init init_idescsi_module(void) |
| 1048 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1049 | return driver_register(&idescsi_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | static void __exit exit_idescsi_module(void) |
| 1053 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1054 | driver_unregister(&idescsi_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
Alan Cox | aaeab80 | 2006-12-06 20:39:33 -0800 | [diff] [blame] | 1057 | module_param(idescsi_nocd, int, 0600); |
| 1058 | MODULE_PARM_DESC(idescsi_nocd, "Disable handling of CD-ROMs so they may be driven by ide-cd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | module_init(init_idescsi_module); |
| 1060 | module_exit(exit_idescsi_module); |
| 1061 | MODULE_LICENSE("GPL"); |