aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/ide-scsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/ide-scsi.c')
-rw-r--r--drivers/scsi/ide-scsi.c203
1 files changed, 90 insertions, 113 deletions
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 68e5c632c5d5..93c3fc20aa59 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -60,31 +60,6 @@
60 60
61#define IDESCSI_DEBUG_LOG 0 61#define IDESCSI_DEBUG_LOG 0
62 62
63typedef 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 */
72 unsigned int sg_cnt; /* Number of entries in sg */
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 */
85#define PC_TIMEDOUT 3 /* command timed out */
86#define PC_DMA_OK 4 /* Use DMA */
87
88/* 63/*
89 * SCSI command transformation layer 64 * SCSI command transformation layer
90 */ 65 */
@@ -101,14 +76,15 @@ typedef struct ide_scsi_obj {
101 struct gendisk *disk; 76 struct gendisk *disk;
102 struct Scsi_Host *host; 77 struct Scsi_Host *host;
103 78
104 idescsi_pc_t *pc; /* Current packet command */ 79 struct ide_atapi_pc *pc; /* Current packet command */
105 unsigned long flags; /* Status/Action flags */ 80 unsigned long flags; /* Status/Action flags */
106 unsigned long transform; /* SCSI cmd translation layer */ 81 unsigned long transform; /* SCSI cmd translation layer */
107 unsigned long log; /* log flags */ 82 unsigned long log; /* log flags */
108} idescsi_scsi_t; 83} idescsi_scsi_t;
109 84
110static DEFINE_MUTEX(idescsi_ref_mutex); 85static DEFINE_MUTEX(idescsi_ref_mutex);
111static int idescsi_nocd; /* Set by module param to skip cd */ 86/* Set by module param to skip cd */
87static int idescsi_nocd;
112 88
113#define ide_scsi_g(disk) \ 89#define ide_scsi_g(disk) \
114 container_of((disk)->private_data, struct ide_scsi_obj, driver) 90 container_of((disk)->private_data, struct ide_scsi_obj, driver)
@@ -152,22 +128,11 @@ static inline idescsi_scsi_t *drive_to_idescsi(ide_drive_t *ide_drive)
152 */ 128 */
153#define IDESCSI_PC_RQ 90 129#define IDESCSI_PC_RQ 90
154 130
155static void idescsi_discard_data (ide_drive_t *drive, unsigned int bcount)
156{
157 while (bcount--)
158 (void) HWIF(drive)->INB(IDE_DATA_REG);
159}
160
161static void idescsi_output_zeros (ide_drive_t *drive, unsigned int bcount)
162{
163 while (bcount--)
164 HWIF(drive)->OUTB(0, IDE_DATA_REG);
165}
166
167/* 131/*
168 * PIO data transfer routines using the scatter gather table. 132 * PIO data transfer routines using the scatter gather table.
169 */ 133 */
170static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) 134static void idescsi_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
135 unsigned int bcount)
171{ 136{
172 int count; 137 int count;
173 char *buf; 138 char *buf;
@@ -200,11 +165,12 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
200 165
201 if (bcount) { 166 if (bcount) {
202 printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n"); 167 printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
203 idescsi_discard_data (drive, bcount); 168 ide_atapi_discard_data(drive, bcount);
204 } 169 }
205} 170}
206 171
207static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigned int bcount) 172static void idescsi_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
173 unsigned int bcount)
208{ 174{
209 int count; 175 int count;
210 char *buf; 176 char *buf;
@@ -237,7 +203,7 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
237 203
238 if (bcount) { 204 if (bcount) {
239 printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n"); 205 printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
240 idescsi_output_zeros (drive, bcount); 206 ide_atapi_write_zeros(drive, bcount);
241 } 207 }
242} 208}
243 209
@@ -246,15 +212,16 @@ static void ide_scsi_hex_dump(u8 *data, int len)
246 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0); 212 print_hex_dump(KERN_CONT, "", DUMP_PREFIX_NONE, 16, 1, data, len, 0);
247} 213}
248 214
249static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_command) 215static int idescsi_check_condition(ide_drive_t *drive,
216 struct request *failed_cmd)
250{ 217{
251 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 218 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
252 idescsi_pc_t *pc; 219 struct ide_atapi_pc *pc;
253 struct request *rq; 220 struct request *rq;
254 u8 *buf; 221 u8 *buf;
255 222
256 /* stuff a sense request in front of our current request */ 223 /* stuff a sense request in front of our current request */
257 pc = kzalloc(sizeof(idescsi_pc_t), GFP_ATOMIC); 224 pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
258 rq = kmalloc(sizeof(struct request), GFP_ATOMIC); 225 rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
259 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC); 226 buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
260 if (!pc || !rq || !buf) { 227 if (!pc || !rq || !buf) {
@@ -266,14 +233,14 @@ static int idescsi_check_condition(ide_drive_t *drive, struct request *failed_co
266 ide_init_drive_cmd(rq); 233 ide_init_drive_cmd(rq);
267 rq->special = (char *) pc; 234 rq->special = (char *) pc;
268 pc->rq = rq; 235 pc->rq = rq;
269 pc->buffer = buf; 236 pc->buf = buf;
270 pc->c[0] = REQUEST_SENSE; 237 pc->c[0] = REQUEST_SENSE;
271 pc->c[4] = pc->request_transfer = pc->buffer_size = SCSI_SENSE_BUFFERSIZE; 238 pc->c[4] = pc->req_xfer = pc->buf_size = SCSI_SENSE_BUFFERSIZE;
272 rq->cmd_type = REQ_TYPE_SENSE; 239 rq->cmd_type = REQ_TYPE_SENSE;
273 pc->timeout = jiffies + WAIT_READY; 240 pc->timeout = jiffies + WAIT_READY;
274 /* NOTE! Save the failed packet command in "rq->buffer" */ 241 /* NOTE! Save the failed packet command in "rq->buffer" */
275 rq->buffer = (void *) failed_command->special; 242 rq->buffer = (void *) failed_cmd->special;
276 pc->scsi_cmd = ((idescsi_pc_t *) failed_command->special)->scsi_cmd; 243 pc->scsi_cmd = ((struct ide_atapi_pc *) failed_cmd->special)->scsi_cmd;
277 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) { 244 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
278 printk ("ide-scsi: %s: queue cmd = ", drive->name); 245 printk ("ide-scsi: %s: queue cmd = ", drive->name);
279 ide_scsi_hex_dump(pc->c, 6); 246 ide_scsi_hex_dump(pc->c, 6);
@@ -287,9 +254,12 @@ static int idescsi_end_request(ide_drive_t *, int, int);
287static ide_startstop_t 254static ide_startstop_t
288idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err) 255idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
289{ 256{
257 ide_hwif_t *hwif = drive->hwif;
258
290 if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT)) 259 if (ide_read_status(drive) & (BUSY_STAT | DRQ_STAT))
291 /* force an abort */ 260 /* force an abort */
292 HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG); 261 hwif->OUTB(WIN_IDLEIMMEDIATE,
262 hwif->io_ports[IDE_COMMAND_OFFSET]);
293 263
294 rq->errors++; 264 rq->errors++;
295 265
@@ -303,7 +273,7 @@ idescsi_atapi_abort(ide_drive_t *drive, struct request *rq)
303{ 273{
304#if IDESCSI_DEBUG_LOG 274#if IDESCSI_DEBUG_LOG
305 printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n", 275 printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n",
306 ((idescsi_pc_t *) rq->special)->scsi_cmd->serial_number); 276 ((struct ide_atapi_pc *) rq->special)->scsi_cmd->serial_number);
307#endif 277#endif
308 rq->errors |= ERROR_MAX; 278 rq->errors |= ERROR_MAX;
309 279
@@ -316,7 +286,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
316{ 286{
317 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 287 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
318 struct request *rq = HWGROUP(drive)->rq; 288 struct request *rq = HWGROUP(drive)->rq;
319 idescsi_pc_t *pc = (idescsi_pc_t *) rq->special; 289 struct ide_atapi_pc *pc = (struct ide_atapi_pc *) rq->special;
320 int log = test_bit(IDESCSI_LOG_CMD, &scsi->log); 290 int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
321 struct Scsi_Host *host; 291 struct Scsi_Host *host;
322 int errors = rq->errors; 292 int errors = rq->errors;
@@ -328,20 +298,23 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
328 } 298 }
329 ide_end_drive_cmd (drive, 0, 0); 299 ide_end_drive_cmd (drive, 0, 0);
330 if (blk_sense_request(rq)) { 300 if (blk_sense_request(rq)) {
331 idescsi_pc_t *opc = (idescsi_pc_t *) rq->buffer; 301 struct ide_atapi_pc *opc = (struct ide_atapi_pc *) rq->buffer;
332 if (log) { 302 if (log) {
333 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number); 303 printk ("ide-scsi: %s: wrap up check %lu, rst = ", drive->name, opc->scsi_cmd->serial_number);
334 ide_scsi_hex_dump(pc->buffer, 16); 304 ide_scsi_hex_dump(pc->buf, 16);
335 } 305 }
336 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buffer, SCSI_SENSE_BUFFERSIZE); 306 memcpy((void *) opc->scsi_cmd->sense_buffer, pc->buf,
337 kfree(pc->buffer); 307 SCSI_SENSE_BUFFERSIZE);
308 kfree(pc->buf);
338 kfree(pc); 309 kfree(pc);
339 kfree(rq); 310 kfree(rq);
340 pc = opc; 311 pc = opc;
341 rq = pc->rq; 312 rq = pc->rq;
342 pc->scsi_cmd->result = (CHECK_CONDITION << 1) | 313 pc->scsi_cmd->result = (CHECK_CONDITION << 1) |
343 ((test_bit(PC_TIMEDOUT, &pc->flags)?DID_TIME_OUT:DID_OK) << 16); 314 (((pc->flags & PC_FLAG_TIMEDOUT) ?
344 } else if (test_bit(PC_TIMEDOUT, &pc->flags)) { 315 DID_TIME_OUT :
316 DID_OK) << 16);
317 } else if (pc->flags & PC_FLAG_TIMEDOUT) {
345 if (log) 318 if (log)
346 printk (KERN_WARNING "ide-scsi: %s: timed out for %lu\n", 319 printk (KERN_WARNING "ide-scsi: %s: timed out for %lu\n",
347 drive->name, pc->scsi_cmd->serial_number); 320 drive->name, pc->scsi_cmd->serial_number);
@@ -370,7 +343,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
370 return 0; 343 return 0;
371} 344}
372 345
373static inline unsigned long get_timeout(idescsi_pc_t *pc) 346static inline unsigned long get_timeout(struct ide_atapi_pc *pc)
374{ 347{
375 return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies); 348 return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
376} 349}
@@ -378,12 +351,12 @@ static inline unsigned long get_timeout(idescsi_pc_t *pc)
378static int idescsi_expiry(ide_drive_t *drive) 351static int idescsi_expiry(ide_drive_t *drive)
379{ 352{
380 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 353 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
381 idescsi_pc_t *pc = scsi->pc; 354 struct ide_atapi_pc *pc = scsi->pc;
382 355
383#if IDESCSI_DEBUG_LOG 356#if IDESCSI_DEBUG_LOG
384 printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies); 357 printk(KERN_WARNING "idescsi_expiry called for %lu at %lu\n", pc->scsi_cmd->serial_number, jiffies);
385#endif 358#endif
386 set_bit(PC_TIMEDOUT, &pc->flags); 359 pc->flags |= PC_FLAG_TIMEDOUT;
387 360
388 return 0; /* we do not want the ide subsystem to retry */ 361 return 0; /* we do not want the ide subsystem to retry */
389} 362}
@@ -395,7 +368,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
395{ 368{
396 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 369 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
397 ide_hwif_t *hwif = drive->hwif; 370 ide_hwif_t *hwif = drive->hwif;
398 idescsi_pc_t *pc = scsi->pc; 371 struct ide_atapi_pc *pc = scsi->pc;
399 struct request *rq = pc->rq; 372 struct request *rq = pc->rq;
400 unsigned int temp; 373 unsigned int temp;
401 u16 bcount; 374 u16 bcount;
@@ -405,7 +378,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
405 printk (KERN_INFO "ide-scsi: Reached idescsi_pc_intr interrupt handler\n"); 378 printk (KERN_INFO "ide-scsi: Reached idescsi_pc_intr interrupt handler\n");
406#endif /* IDESCSI_DEBUG_LOG */ 379#endif /* IDESCSI_DEBUG_LOG */
407 380
408 if (test_bit(PC_TIMEDOUT, &pc->flags)){ 381 if (pc->flags & PC_FLAG_TIMEDOUT) {
409#if IDESCSI_DEBUG_LOG 382#if IDESCSI_DEBUG_LOG
410 printk(KERN_WARNING "idescsi_pc_intr: got timed out packet %lu at %lu\n", 383 printk(KERN_WARNING "idescsi_pc_intr: got timed out packet %lu at %lu\n",
411 pc->scsi_cmd->serial_number, jiffies); 384 pc->scsi_cmd->serial_number, jiffies);
@@ -414,11 +387,12 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
414 idescsi_end_request (drive, 1, 0); 387 idescsi_end_request (drive, 1, 0);
415 return ide_stopped; 388 return ide_stopped;
416 } 389 }
417 if (test_and_clear_bit (PC_DMA_IN_PROGRESS, &pc->flags)) { 390 if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
391 pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
418#if IDESCSI_DEBUG_LOG 392#if IDESCSI_DEBUG_LOG
419 printk ("ide-scsi: %s: DMA complete\n", drive->name); 393 printk ("ide-scsi: %s: DMA complete\n", drive->name);
420#endif /* IDESCSI_DEBUG_LOG */ 394#endif /* IDESCSI_DEBUG_LOG */
421 pc->actually_transferred=pc->request_transfer; 395 pc->xferred = pc->req_xfer;
422 (void) HWIF(drive)->ide_dma_end(drive); 396 (void) HWIF(drive)->ide_dma_end(drive);
423 } 397 }
424 398
@@ -428,42 +402,44 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
428 if ((stat & DRQ_STAT) == 0) { 402 if ((stat & DRQ_STAT) == 0) {
429 /* No more interrupts */ 403 /* No more interrupts */
430 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) 404 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
431 printk (KERN_INFO "Packet command completed, %d bytes transferred\n", pc->actually_transferred); 405 printk(KERN_INFO "Packet command completed, %d bytes"
406 " transferred\n", pc->xferred);
432 local_irq_enable_in_hardirq(); 407 local_irq_enable_in_hardirq();
433 if (stat & ERR_STAT) 408 if (stat & ERR_STAT)
434 rq->errors++; 409 rq->errors++;
435 idescsi_end_request (drive, 1, 0); 410 idescsi_end_request (drive, 1, 0);
436 return ide_stopped; 411 return ide_stopped;
437 } 412 }
438 bcount = (hwif->INB(IDE_BCOUNTH_REG) << 8) | 413 bcount = (hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]) << 8) |
439 hwif->INB(IDE_BCOUNTL_REG); 414 hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]);
440 ireason = hwif->INB(IDE_IREASON_REG); 415 ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]);
441 416
442 if (ireason & CD) { 417 if (ireason & CD) {
443 printk(KERN_ERR "ide-scsi: CoD != 0 in idescsi_pc_intr\n"); 418 printk(KERN_ERR "ide-scsi: CoD != 0 in idescsi_pc_intr\n");
444 return ide_do_reset (drive); 419 return ide_do_reset (drive);
445 } 420 }
446 if (ireason & IO) { 421 if (ireason & IO) {
447 temp = pc->actually_transferred + bcount; 422 temp = pc->xferred + bcount;
448 if (temp > pc->request_transfer) { 423 if (temp > pc->req_xfer) {
449 if (temp > pc->buffer_size) { 424 if (temp > pc->buf_size) {
450 printk(KERN_ERR "ide-scsi: The scsi wants to " 425 printk(KERN_ERR "ide-scsi: The scsi wants to "
451 "send us more data than expected " 426 "send us more data than expected "
452 "- discarding data\n"); 427 "- discarding data\n");
453 temp = pc->buffer_size - pc->actually_transferred; 428 temp = pc->buf_size - pc->xferred;
454 if (temp) { 429 if (temp) {
455 clear_bit(PC_WRITING, &pc->flags); 430 pc->flags &= ~PC_FLAG_WRITING;
456 if (pc->sg) 431 if (pc->sg)
457 idescsi_input_buffers(drive, pc, temp); 432 idescsi_input_buffers(drive, pc,
433 temp);
458 else 434 else
459 drive->hwif->atapi_input_bytes(drive, pc->current_position, temp); 435 drive->hwif->atapi_input_bytes(drive, pc->cur_pos, temp);
460 printk(KERN_ERR "ide-scsi: transferred" 436 printk(KERN_ERR "ide-scsi: transferred"
461 " %d of %d bytes\n", 437 " %d of %d bytes\n",
462 temp, bcount); 438 temp, bcount);
463 } 439 }
464 pc->actually_transferred += temp; 440 pc->xferred += temp;
465 pc->current_position += temp; 441 pc->cur_pos += temp;
466 idescsi_discard_data(drive, bcount - temp); 442 ide_atapi_discard_data(drive, bcount - temp);
467 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); 443 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
468 return ide_started; 444 return ide_started;
469 } 445 }
@@ -473,23 +449,23 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
473 } 449 }
474 } 450 }
475 if (ireason & IO) { 451 if (ireason & IO) {
476 clear_bit(PC_WRITING, &pc->flags); 452 pc->flags &= ~PC_FLAG_WRITING;
477 if (pc->sg) 453 if (pc->sg)
478 idescsi_input_buffers(drive, pc, bcount); 454 idescsi_input_buffers(drive, pc, bcount);
479 else 455 else
480 hwif->atapi_input_bytes(drive, pc->current_position, 456 hwif->atapi_input_bytes(drive, pc->cur_pos,
481 bcount); 457 bcount);
482 } else { 458 } else {
483 set_bit(PC_WRITING, &pc->flags); 459 pc->flags |= PC_FLAG_WRITING;
484 if (pc->sg) 460 if (pc->sg)
485 idescsi_output_buffers(drive, pc, bcount); 461 idescsi_output_buffers(drive, pc, bcount);
486 else 462 else
487 hwif->atapi_output_bytes(drive, pc->current_position, 463 hwif->atapi_output_bytes(drive, pc->cur_pos,
488 bcount); 464 bcount);
489 } 465 }
490 /* Update the current position */ 466 /* Update the current position */
491 pc->actually_transferred += bcount; 467 pc->xferred += bcount;
492 pc->current_position += bcount; 468 pc->cur_pos += bcount;
493 469
494 /* And set the interrupt handler again */ 470 /* And set the interrupt handler again */
495 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); 471 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
@@ -500,7 +476,7 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
500{ 476{
501 ide_hwif_t *hwif = drive->hwif; 477 ide_hwif_t *hwif = drive->hwif;
502 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 478 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
503 idescsi_pc_t *pc = scsi->pc; 479 struct ide_atapi_pc *pc = scsi->pc;
504 ide_startstop_t startstop; 480 ide_startstop_t startstop;
505 u8 ireason; 481 u8 ireason;
506 482
@@ -509,7 +485,7 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
509 "initiated yet DRQ isn't asserted\n"); 485 "initiated yet DRQ isn't asserted\n");
510 return startstop; 486 return startstop;
511 } 487 }
512 ireason = hwif->INB(IDE_IREASON_REG); 488 ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]);
513 if ((ireason & CD) == 0 || (ireason & IO)) { 489 if ((ireason & CD) == 0 || (ireason & IO)) {
514 printk(KERN_ERR "ide-scsi: (IO,CoD) != (0,1) while " 490 printk(KERN_ERR "ide-scsi: (IO,CoD) != (0,1) while "
515 "issuing a packet command\n"); 491 "issuing a packet command\n");
@@ -520,34 +496,34 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
520 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry); 496 ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
521 /* Send the actual packet */ 497 /* Send the actual packet */
522 drive->hwif->atapi_output_bytes(drive, scsi->pc->c, 12); 498 drive->hwif->atapi_output_bytes(drive, scsi->pc->c, 12);
523 if (test_bit (PC_DMA_OK, &pc->flags)) { 499 if (pc->flags & PC_FLAG_DMA_OK) {
524 set_bit (PC_DMA_IN_PROGRESS, &pc->flags); 500 pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
525 hwif->dma_start(drive); 501 hwif->dma_start(drive);
526 } 502 }
527 return ide_started; 503 return ide_started;
528} 504}
529 505
530static inline int idescsi_set_direction(idescsi_pc_t *pc) 506static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
531{ 507{
532 switch (pc->c[0]) { 508 switch (pc->c[0]) {
533 case READ_6: case READ_10: case READ_12: 509 case READ_6: case READ_10: case READ_12:
534 clear_bit(PC_WRITING, &pc->flags); 510 pc->flags &= ~PC_FLAG_WRITING;
535 return 0; 511 return 0;
536 case WRITE_6: case WRITE_10: case WRITE_12: 512 case WRITE_6: case WRITE_10: case WRITE_12:
537 set_bit(PC_WRITING, &pc->flags); 513 pc->flags |= PC_FLAG_WRITING;
538 return 0; 514 return 0;
539 default: 515 default:
540 return 1; 516 return 1;
541 } 517 }
542} 518}
543 519
544static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc) 520static int idescsi_map_sg(ide_drive_t *drive, struct ide_atapi_pc *pc)
545{ 521{
546 ide_hwif_t *hwif = drive->hwif; 522 ide_hwif_t *hwif = drive->hwif;
547 struct scatterlist *sg, *scsi_sg; 523 struct scatterlist *sg, *scsi_sg;
548 int segments; 524 int segments;
549 525
550 if (!pc->request_transfer || pc->request_transfer % 1024) 526 if (!pc->req_xfer || pc->req_xfer % 1024)
551 return 1; 527 return 1;
552 528
553 if (idescsi_set_direction(pc)) 529 if (idescsi_set_direction(pc))
@@ -566,21 +542,21 @@ static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc)
566 return 0; 542 return 0;
567} 543}
568 544
569/* 545static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
570 * Issue a packet command 546 struct ide_atapi_pc *pc)
571 */
572static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
573{ 547{
574 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 548 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
575 ide_hwif_t *hwif = drive->hwif; 549 ide_hwif_t *hwif = drive->hwif;
576 u16 bcount; 550 u16 bcount;
577 u8 dma = 0; 551 u8 dma = 0;
578 552
579 scsi->pc=pc; /* Set the current packet command */ 553 /* Set the current packet command */
580 pc->actually_transferred=0; /* We haven't transferred any data yet */ 554 scsi->pc = pc;
581 pc->current_position=pc->buffer; 555 /* We haven't transferred any data yet */
556 pc->xferred = 0;
557 pc->cur_pos = pc->buf;
582 /* Request to transfer the entire buffer at once */ 558 /* Request to transfer the entire buffer at once */
583 bcount = min(pc->request_transfer, 63 * 1024); 559 bcount = min(pc->req_xfer, 63 * 1024);
584 560
585 if (drive->using_dma && !idescsi_map_sg(drive, pc)) { 561 if (drive->using_dma && !idescsi_map_sg(drive, pc)) {
586 hwif->sg_mapped = 1; 562 hwif->sg_mapped = 1;
@@ -591,7 +567,7 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
591 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK, bcount, dma); 567 ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK, bcount, dma);
592 568
593 if (dma) 569 if (dma)
594 set_bit(PC_DMA_OK, &pc->flags); 570 pc->flags |= PC_FLAG_DMA_OK;
595 571
596 if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) { 572 if (test_bit(IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
597 ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc, 573 ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc,
@@ -599,7 +575,7 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
599 return ide_started; 575 return ide_started;
600 } else { 576 } else {
601 /* Issue the packet command */ 577 /* Issue the packet command */
602 HWIF(drive)->OUTB(WIN_PACKETCMD, IDE_COMMAND_REG); 578 hwif->OUTB(WIN_PACKETCMD, hwif->io_ports[IDE_COMMAND_OFFSET]);
603 return idescsi_transfer_pc(drive); 579 return idescsi_transfer_pc(drive);
604 } 580 }
605} 581}
@@ -615,7 +591,8 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
615#endif /* IDESCSI_DEBUG_LOG */ 591#endif /* IDESCSI_DEBUG_LOG */
616 592
617 if (blk_sense_request(rq) || blk_special_request(rq)) { 593 if (blk_sense_request(rq) || blk_special_request(rq)) {
618 return idescsi_issue_pc (drive, (idescsi_pc_t *) rq->special); 594 return idescsi_issue_pc(drive,
595 (struct ide_atapi_pc *) rq->special);
619 } 596 }
620 blk_dump_rq_flags(rq, "ide-scsi: unsup command"); 597 blk_dump_rq_flags(rq, "ide-scsi: unsup command");
621 idescsi_end_request (drive, 0, 0); 598 idescsi_end_request (drive, 0, 0);
@@ -773,15 +750,15 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
773 idescsi_scsi_t *scsi = scsihost_to_idescsi(host); 750 idescsi_scsi_t *scsi = scsihost_to_idescsi(host);
774 ide_drive_t *drive = scsi->drive; 751 ide_drive_t *drive = scsi->drive;
775 struct request *rq = NULL; 752 struct request *rq = NULL;
776 idescsi_pc_t *pc = NULL; 753 struct ide_atapi_pc *pc = NULL;
777 754
778 if (!drive) { 755 if (!drive) {
779 scmd_printk (KERN_ERR, cmd, "drive not present\n"); 756 scmd_printk (KERN_ERR, cmd, "drive not present\n");
780 goto abort; 757 goto abort;
781 } 758 }
782 scsi = drive_to_idescsi(drive); 759 scsi = drive_to_idescsi(drive);
783 pc = kmalloc (sizeof (idescsi_pc_t), GFP_ATOMIC); 760 pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
784 rq = kmalloc (sizeof (struct request), GFP_ATOMIC); 761 rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
785 if (rq == NULL || pc == NULL) { 762 if (rq == NULL || pc == NULL) {
786 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name); 763 printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
787 goto abort; 764 goto abort;
@@ -791,11 +768,11 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
791 pc->flags = 0; 768 pc->flags = 0;
792 pc->rq = rq; 769 pc->rq = rq;
793 memcpy (pc->c, cmd->cmnd, cmd->cmd_len); 770 memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
794 pc->buffer = NULL; 771 pc->buf = NULL;
795 pc->sg = scsi_sglist(cmd); 772 pc->sg = scsi_sglist(cmd);
796 pc->sg_cnt = scsi_sg_count(cmd); 773 pc->sg_cnt = scsi_sg_count(cmd);
797 pc->b_count = 0; 774 pc->b_count = 0;
798 pc->request_transfer = pc->buffer_size = scsi_bufflen(cmd); 775 pc->req_xfer = pc->buf_size = scsi_bufflen(cmd);
799 pc->scsi_cmd = cmd; 776 pc->scsi_cmd = cmd;
800 pc->done = done; 777 pc->done = done;
801 pc->timeout = jiffies + cmd->timeout_per_command; 778 pc->timeout = jiffies + cmd->timeout_per_command;
@@ -866,7 +843,7 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
866 printk (KERN_ERR "ide-scsi: cmd aborted!\n"); 843 printk (KERN_ERR "ide-scsi: cmd aborted!\n");
867 844
868 if (blk_sense_request(scsi->pc->rq)) 845 if (blk_sense_request(scsi->pc->rq))
869 kfree(scsi->pc->buffer); 846 kfree(scsi->pc->buf);
870 kfree(scsi->pc->rq); 847 kfree(scsi->pc->rq);
871 kfree(scsi->pc); 848 kfree(scsi->pc);
872 scsi->pc = NULL; 849 scsi->pc = NULL;
@@ -916,7 +893,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
916 if (__blk_end_request(req, -EIO, 0)) 893 if (__blk_end_request(req, -EIO, 0))
917 BUG(); 894 BUG();
918 if (blk_sense_request(req)) 895 if (blk_sense_request(req))
919 kfree(scsi->pc->buffer); 896 kfree(scsi->pc->buf);
920 kfree(scsi->pc); 897 kfree(scsi->pc);
921 scsi->pc = NULL; 898 scsi->pc = NULL;
922 kfree(req); 899 kfree(req);