1010
1111#include <scsi/scsi.h>
1212
13+ #define DRV_NAME "ide-atapi"
14+ #define PFX DRV_NAME ": "
15+
1316#ifdef DEBUG
1417#define debug_log (fmt , args ...) \
1518 printk(KERN_INFO "ide: " fmt, ## args)
@@ -197,8 +200,8 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
197200 GFP_NOIO );
198201 if (unlikely (err )) {
199202 if (printk_ratelimit ())
200- printk (KERN_WARNING "%s: failed to map sense buffer\n" ,
201- drive -> name );
203+ printk (KERN_WARNING PFX "%s: failed to map sense "
204+ "buffer\n" , drive -> name );
202205 return ;
203206 }
204207
@@ -219,7 +222,7 @@ int ide_queue_sense_rq(ide_drive_t *drive, void *special)
219222{
220223 /* deferred failure from ide_prep_sense() */
221224 if (!drive -> sense_rq_armed ) {
222- printk (KERN_WARNING "%s: failed queue sense request\n" ,
225+ printk (KERN_WARNING PFX "%s: error queuing a sense request\n" ,
223226 drive -> name );
224227 return - ENOMEM ;
225228 }
@@ -292,7 +295,7 @@ int ide_cd_expiry(ide_drive_t *drive)
292295 break ;
293296 default :
294297 if (!(rq -> cmd_flags & REQ_QUIET ))
295- printk (KERN_INFO "cmd 0x%x timed out\n" ,
298+ printk (KERN_INFO PFX "cmd 0x%x timed out\n" ,
296299 rq -> cmd [0 ]);
297300 wait = 0 ;
298301 break ;
@@ -325,6 +328,55 @@ void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
325328}
326329EXPORT_SYMBOL_GPL (ide_read_bcount_and_ireason );
327330
331+ /*
332+ * Check the contents of the interrupt reason register and attempt to recover if
333+ * there are problems.
334+ *
335+ * Returns:
336+ * - 0 if everything's ok
337+ * - 1 if the request has to be terminated.
338+ */
339+ int ide_check_ireason (ide_drive_t * drive , struct request * rq , int len ,
340+ int ireason , int rw )
341+ {
342+ ide_hwif_t * hwif = drive -> hwif ;
343+
344+ debug_log ("ireason: 0x%x, rw: 0x%x\n" , ireason , rw );
345+
346+ if (ireason == (!rw << 1 ))
347+ return 0 ;
348+ else if (ireason == (rw << 1 )) {
349+ printk (KERN_ERR PFX "%s: %s: wrong transfer direction!\n" ,
350+ drive -> name , __func__ );
351+
352+ if (dev_is_idecd (drive ))
353+ ide_pad_transfer (drive , rw , len );
354+ } else if (!rw && ireason == ATAPI_COD ) {
355+ if (dev_is_idecd (drive )) {
356+ /*
357+ * Some drives (ASUS) seem to tell us that status info
358+ * is available. Just get it and ignore.
359+ */
360+ (void )hwif -> tp_ops -> read_status (hwif );
361+ return 0 ;
362+ }
363+ } else {
364+ if (ireason & ATAPI_COD )
365+ printk (KERN_ERR PFX "%s: CoD != 0 in %s\n" , drive -> name ,
366+ __func__ );
367+
368+ /* drive wants a command packet, or invalid ireason... */
369+ printk (KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n" ,
370+ drive -> name , __func__ , ireason );
371+ }
372+
373+ if (dev_is_idecd (drive ) && rq -> cmd_type == REQ_TYPE_ATA_PC )
374+ rq -> cmd_flags |= REQ_FAILED ;
375+
376+ return 1 ;
377+ }
378+ EXPORT_SYMBOL_GPL (ide_check_ireason );
379+
328380/*
329381 * This is the usual interrupt handler which will be called during a packet
330382 * command. We will transfer some of the data (as requested by the drive)
@@ -359,7 +411,7 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
359411
360412 if (rc || (drive -> media == ide_tape && (stat & ATA_ERR ))) {
361413 if (drive -> media == ide_floppy )
362- printk (KERN_ERR "%s: DMA %s error\n" ,
414+ printk (KERN_ERR PFX "%s: DMA %s error\n" ,
363415 drive -> name , rq_data_dir (pc -> rq )
364416 ? "write" : "read" );
365417 pc -> flags |= PC_FLAG_DMA_ERROR ;
@@ -391,8 +443,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
391443 pc -> rq -> errors ++ ;
392444
393445 if (rq -> cmd [0 ] == REQUEST_SENSE ) {
394- printk (KERN_ERR "%s: I/O error in request sense "
395- " command\n" , drive -> name );
446+ printk (KERN_ERR PFX "%s: I/O error in request "
447+ "sense command\n" , drive -> name );
396448 return ide_do_reset (drive );
397449 }
398450
@@ -434,28 +486,17 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
434486
435487 if (pc -> flags & PC_FLAG_DMA_IN_PROGRESS ) {
436488 pc -> flags &= ~PC_FLAG_DMA_IN_PROGRESS ;
437- printk (KERN_ERR "%s: The device wants to issue more interrupts "
438- "in DMA mode\n" , drive -> name );
489+ printk (KERN_ERR PFX "%s: The device wants to issue more "
490+ "interrupts in DMA mode\n" , drive -> name );
439491 ide_dma_off (drive );
440492 return ide_do_reset (drive );
441493 }
442494
443495 /* Get the number of bytes to transfer on this interrupt. */
444496 ide_read_bcount_and_ireason (drive , & bcount , & ireason );
445497
446- if (ireason & ATAPI_COD ) {
447- printk (KERN_ERR "%s: CoD != 0 in %s\n" , drive -> name , __func__ );
498+ if (ide_check_ireason (drive , rq , bcount , ireason , write ))
448499 return ide_do_reset (drive );
449- }
450-
451- if (((ireason & ATAPI_IO ) == ATAPI_IO ) == write ) {
452- /* Hopefully, we will never get here */
453- printk (KERN_ERR "%s: We wanted to %s, but the device wants us "
454- "to %s!\n" , drive -> name ,
455- (ireason & ATAPI_IO ) ? "Write" : "Read" ,
456- (ireason & ATAPI_IO ) ? "Read" : "Write" );
457- return ide_do_reset (drive );
458- }
459500
460501 done = min_t (unsigned int , bcount , cmd -> nleft );
461502 ide_pio_bytes (drive , cmd , write , done );
@@ -503,13 +544,13 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
503544
504545 while (retries -- && ((ireason & ATAPI_COD ) == 0 ||
505546 (ireason & ATAPI_IO ))) {
506- printk (KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
547+ printk (KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing "
507548 "a packet command, retrying\n" , drive -> name );
508549 udelay (100 );
509550 ireason = ide_read_ireason (drive );
510551 if (retries == 0 ) {
511- printk (KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
512- "a packet command, ignoring\n" ,
552+ printk (KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing"
553+ " a packet command, ignoring\n" ,
513554 drive -> name );
514555 ireason |= ATAPI_COD ;
515556 ireason &= ~ATAPI_IO ;
@@ -540,7 +581,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
540581 u8 ireason ;
541582
542583 if (ide_wait_stat (& startstop , drive , ATA_DRQ , ATA_BUSY , WAIT_READY )) {
543- printk (KERN_ERR "%s: Strange, packet command initiated yet "
584+ printk (KERN_ERR PFX "%s: Strange, packet command initiated yet "
544585 "DRQ isn't asserted\n" , drive -> name );
545586 return startstop ;
546587 }
@@ -582,8 +623,8 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
582623 ireason = ide_wait_ireason (drive , ireason );
583624
584625 if ((ireason & ATAPI_COD ) == 0 || (ireason & ATAPI_IO )) {
585- printk (KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
586- " a packet command\n" , drive -> name );
626+ printk (KERN_ERR PFX "%s: (IO,CoD) != (0,1) while "
627+ "issuing a packet command\n" , drive -> name );
587628
588629 return ide_do_reset (drive );
589630 }
0 commit comments