ide: add ide_issue_pc() helper
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Tue, 15 Jul 2008 19:22:00 +0000 (21:22 +0200)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Tue, 15 Jul 2008 19:22:00 +0000 (21:22 +0200)
Add generic ide_issue_pc() helper to ide-atapi.c and then
convert ide-{floppy,tape,scsi} device drivers to use it.

There should be no functional changes caused by this patch.

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/ide-atapi.c
drivers/ide/ide-floppy.c
drivers/ide/ide-tape.c
drivers/scsi/ide-scsi.c
include/linux/ide.h

index 25939bc6040261fd064a0cf5ad9f3f97a2b1971b..932a83abaf069e992179604129044cae169807eb 100644 (file)
@@ -68,3 +68,52 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
        return ide_started;
 }
 EXPORT_SYMBOL_GPL(ide_transfer_pc);
+
+ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
+                            ide_handler_t *handler, unsigned int timeout,
+                            ide_expiry_t *expiry)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u16 bcount;
+       u8 dma = 0;
+
+       /* We haven't transferred any data yet */
+       pc->xferred = 0;
+       pc->cur_pos = pc->buf;
+
+       /* Request to transfer the entire buffer at once */
+       if (drive->media == ide_tape && !drive->scsi)
+               bcount = pc->req_xfer;
+       else
+               bcount = min(pc->req_xfer, 63 * 1024);
+
+       if (pc->flags & PC_FLAG_DMA_ERROR) {
+               pc->flags &= ~PC_FLAG_DMA_ERROR;
+               ide_dma_off(drive);
+       }
+
+       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) {
+               if (drive->scsi)
+                       hwif->sg_mapped = 1;
+               dma = !hwif->dma_ops->dma_setup(drive);
+               if (drive->scsi)
+                       hwif->sg_mapped = 0;
+       }
+
+       if (!dma)
+               pc->flags &= ~PC_FLAG_DMA_OK;
+
+       ide_pktcmd_tf_load(drive, drive->scsi ? 0 : IDE_TFLAG_OUT_DEVICE,
+                          bcount, dma);
+
+       /* Issue the packet command */
+       if (pc->flags & PC_FLAG_DRQ_INTERRUPT) {
+               ide_execute_command(drive, WIN_PACKETCMD, handler,
+                                   timeout, NULL);
+               return ide_started;
+       } else {
+               ide_execute_pkt_cmd(drive);
+               return (*handler)(drive);
+       }
+}
+EXPORT_SYMBOL_GPL(ide_issue_pc);
index 13f650fa2125e58b6f4b1570ba8527c55cf32905..e658aafc51dac6db5f8e5c074ef14cbc120743c4 100644 (file)
@@ -576,9 +576,6 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
-       ide_hwif_t *hwif = drive->hwif;
-       u16 bcount;
-       u8 dma;
 
        if (floppy->failed_pc == NULL &&
            pc->c[0] != GPCMD_REQUEST_SENSE)
@@ -600,37 +597,9 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
        debug_log("Retry number - %d\n", pc->retries);
 
        pc->retries++;
-       /* We haven't transferred any data yet */
-       pc->xferred = 0;
-       pc->cur_pos = pc->buf;
-       bcount = min(pc->req_xfer, 63 * 1024);
-
-       if (pc->flags & PC_FLAG_DMA_ERROR) {
-               pc->flags &= ~PC_FLAG_DMA_ERROR;
-               ide_dma_off(drive);
-       }
-       dma = 0;
 
-       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma)
-               dma = !hwif->dma_ops->dma_setup(drive);
-
-       if (!dma)
-               pc->flags &= ~PC_FLAG_DMA_OK;
-
-       ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_DEVICE, bcount, dma);
-
-       if (pc->flags & PC_FLAG_DRQ_INTERRUPT) {
-               /* Issue the packet command */
-               ide_execute_command(drive, WIN_PACKETCMD,
-                               &idefloppy_transfer_pc1,
-                               IDEFLOPPY_WAIT_CMD,
-                               NULL);
-               return ide_started;
-       } else {
-               /* Issue the packet command */
-               ide_execute_pkt_cmd(drive);
-               return idefloppy_transfer_pc1(drive);
-       }
+       return ide_issue_pc(drive, pc, idefloppy_transfer_pc1,
+                           IDEFLOPPY_WAIT_CMD, NULL);
 }
 
 static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
index cba18a6755063c310ceb511228ddb0cdc2901683..7907a1e41918491318c09f1aec042b77be0e552c 100644 (file)
@@ -958,10 +958,7 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
 static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
-       ide_hwif_t *hwif = drive->hwif;
        idetape_tape_t *tape = drive->driver_data;
-       int dma_ok = 0;
-       u16 bcount;
 
        if (tape->pc->c[0] == REQUEST_SENSE &&
            pc->c[0] == REQUEST_SENSE) {
@@ -1002,32 +999,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
        debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
 
        pc->retries++;
-       /* We haven't transferred any data yet */
-       pc->xferred = 0;
-       pc->cur_pos = pc->buf;
-       /* Request to transfer the entire buffer at once */
-       bcount = pc->req_xfer;
-
-       if (pc->flags & PC_FLAG_DMA_ERROR) {
-               pc->flags &= ~PC_FLAG_DMA_ERROR;
-               ide_dma_off(drive);
-       }
-       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma)
-               dma_ok = !hwif->dma_ops->dma_setup(drive);
-
-       if (!dma_ok)
-               pc->flags &= ~PC_FLAG_DMA_OK;
-
-       ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_DEVICE, bcount, dma_ok);
 
-       if (pc->flags & PC_FLAG_DRQ_INTERRUPT) {
-               ide_execute_command(drive, WIN_PACKETCMD, &idetape_transfer_pc,
-                                   IDETAPE_WAIT_CMD, NULL);
-               return ide_started;
-       } else {
-               ide_execute_pkt_cmd(drive);
-               return idetape_transfer_pc(drive);
-       }
+       return ide_issue_pc(drive, pc, idetape_transfer_pc,
+                           IDETAPE_WAIT_CMD, NULL);
 }
 
 /* A mode sense command is used to "sense" tape parameters. */
index b7c5e8391575caf0344b062fffe4b4a46974629f..32415466fbfe5a192131df8759dd1d69742fa5b8 100644 (file)
@@ -502,38 +502,12 @@ static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       ide_hwif_t *hwif = drive->hwif;
-       u16 bcount;
-       u8 dma = 0;
 
        /* Set the current packet command */
        scsi->pc = pc;
-       /* We haven't transferred any data yet */
-       pc->xferred = 0;
-       pc->cur_pos = pc->buf;
-       /* Request to transfer the entire buffer at once */
-       bcount = min(pc->req_xfer, 63 * 1024);
-
-       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) {
-               hwif->sg_mapped = 1;
-               dma = !hwif->dma_ops->dma_setup(drive);
-               hwif->sg_mapped = 0;
-       }
-
-       if (!dma)
-               pc->flags &= ~PC_FLAG_DMA_OK;
 
-       ide_pktcmd_tf_load(drive, 0, bcount, dma);
-
-       if (pc->flags & PC_FLAG_DRQ_INTERRUPT) {
-               ide_execute_command(drive, WIN_PACKETCMD, &idescsi_transfer_pc,
-                                   get_timeout(pc), idescsi_expiry);
-               return ide_started;
-       } else {
-               /* Issue the packet command */
-               ide_execute_pkt_cmd(drive);
-               return idescsi_transfer_pc(drive);
-       }
+       return ide_issue_pc(drive, pc, idescsi_transfer_pc,
+                           get_timeout(pc), idescsi_expiry);
 }
 
 /*
index c2274ad44b2e239c4ea50db2b8e5df1325aefe10..fee07a7edb199e8fef1bf65b111a6de2d45ca38e 100644 (file)
@@ -970,6 +970,8 @@ void ide_pktcmd_tf_load(ide_drive_t *, u32, u16, u8);
 
 ide_startstop_t ide_transfer_pc(ide_drive_t *, struct ide_atapi_pc *,
                                ide_handler_t *, unsigned int, ide_expiry_t *);
+ide_startstop_t ide_issue_pc(ide_drive_t *, struct ide_atapi_pc *,
+                            ide_handler_t *, unsigned int, ide_expiry_t *);
 
 ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);