Skip to content

Commit 103f703

Browse files
author
Borislav Petkov
committed
ide: unify interrupt reason checking
Add ide_check_ireason() function that handles all ATAPI devices. Reorganize all unlikely cases in ireason checking further down in the code path. In addition, add PFX for printks originating from ide-atapi. Finally, remove ide_cd_check_ireason. Signed-off-by: Borislav Petkov <petkovbb@gmail.com>
1 parent 239f7e2 commit 103f703

3 files changed

Lines changed: 71 additions & 73 deletions

File tree

‎drivers/ide/ide-atapi.c‎

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
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
}
326329
EXPORT_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
}

‎drivers/ide/ide-cd.c‎

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -410,50 +410,6 @@ static int cdrom_decode_status(ide_drive_t *drive, u8 stat)
410410
return 2;
411411
}
412412

413-
/*
414-
* Check the contents of the interrupt reason register from the cdrom
415-
* and attempt to recover if there are problems. Returns 0 if everything's
416-
* ok; nonzero if the request has been terminated.
417-
*/
418-
static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
419-
int len, int ireason, int rw)
420-
{
421-
ide_hwif_t *hwif = drive->hwif;
422-
423-
ide_debug_log(IDE_DBG_FUNC, "ireason: 0x%x, rw: 0x%x", ireason, rw);
424-
425-
/*
426-
* ireason == 0: the drive wants to receive data from us
427-
* ireason == 2: the drive is expecting to transfer data to us
428-
*/
429-
if (ireason == (!rw << 1))
430-
return 0;
431-
else if (ireason == (rw << 1)) {
432-
433-
/* whoops... */
434-
printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
435-
drive->name, __func__);
436-
437-
ide_pad_transfer(drive, rw, len);
438-
} else if (rw == 0 && ireason == 1) {
439-
/*
440-
* Some drives (ASUS) seem to tell us that status info is
441-
* available. Just get it and ignore.
442-
*/
443-
(void)hwif->tp_ops->read_status(hwif);
444-
return 0;
445-
} else {
446-
/* drive wants a command packet, or invalid ireason... */
447-
printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
448-
drive->name, __func__, ireason);
449-
}
450-
451-
if (rq->cmd_type == REQ_TYPE_ATA_PC)
452-
rq->cmd_flags |= REQ_FAILED;
453-
454-
return -1;
455-
}
456-
457413
static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct ide_cmd *cmd)
458414
{
459415
struct request *rq = cmd->rq;
@@ -645,8 +601,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
645601
goto out_end;
646602
}
647603

648-
/* check which way to transfer data */
649-
rc = ide_cd_check_ireason(drive, rq, len, ireason, write);
604+
rc = ide_check_ireason(drive, rq, len, ireason, write);
650605
if (rc)
651606
goto out_end;
652607

‎include/linux/ide.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ void SELECT_MASK(ide_drive_t *, int);
11251125
u8 ide_read_error(ide_drive_t *);
11261126
void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *);
11271127

1128+
int ide_check_ireason(ide_drive_t *, struct request *, int, int, int);
1129+
11281130
int ide_check_atapi_device(ide_drive_t *, const char *);
11291131

11301132
void ide_init_pc(struct ide_atapi_pc *);

0 commit comments

Comments
 (0)