]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - drivers/ide/ide-tape.c
ide-{floppy,tape}: PC_FLAG_DMA_RECOMMENDED -> PC_FLAG_DMA_OK
[linux-2.6.git] / drivers / ide / ide-tape.c
index cc70e759fc8e156a264d7a72215a3e786cc9eb04..e8a5852fa2d40979368038ddef3548531cd905a2 100644 (file)
@@ -503,18 +503,6 @@ static struct request *idetape_next_rq_storage(ide_drive_t *drive)
        return (&tape->rq_stack[tape->rq_stack_index++]);
 }
 
-static void idetape_init_pc(struct ide_atapi_pc *pc)
-{
-       memset(pc->c, 0, 12);
-       pc->retries = 0;
-       pc->flags = 0;
-       pc->req_xfer = 0;
-       pc->buf = pc->pc_buf;
-       pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
-       pc->bh = NULL;
-       pc->b_data = NULL;
-}
-
 /*
  * called on each failed packet command retry to analyze the request sense. We
  * currently do not utilize this information.
@@ -631,21 +619,75 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
        return 0;
 }
 
-static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive)
+static void ide_tape_callback(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
+       struct ide_atapi_pc *pc = tape->pc;
+       int uptodate = pc->error ? 0 : 1;
 
        debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
-       if (!tape->pc->error) {
-               idetape_analyze_error(drive, tape->pc->buf);
-               idetape_end_request(drive, 1, 0);
-       } else {
-               printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - "
-                               "Aborting request!\n");
-               idetape_end_request(drive, 0, 0);
+       if (pc->c[0] == REQUEST_SENSE) {
+               if (uptodate)
+                       idetape_analyze_error(drive, pc->buf);
+               else
+                       printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
+                                       "itself - Aborting request!\n");
+       } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
+               struct request *rq = drive->hwif->hwgroup->rq;
+               int blocks = pc->xferred / tape->blk_size;
+
+               tape->avg_size += blocks * tape->blk_size;
+
+               if (time_after_eq(jiffies, tape->avg_time + HZ)) {
+                       tape->avg_speed = tape->avg_size * HZ /
+                               (jiffies - tape->avg_time) / 1024;
+                       tape->avg_size = 0;
+                       tape->avg_time = jiffies;
+               }
+
+               tape->first_frame += blocks;
+               rq->current_nr_sectors -= blocks;
+
+               if (pc->error)
+                       uptodate = pc->error;
+       } else if (pc->c[0] == READ_POSITION && uptodate) {
+               u8 *readpos = tape->pc->buf;
+
+               debug_log(DBG_SENSE, "BOP - %s\n",
+                               (readpos[0] & 0x80) ? "Yes" : "No");
+               debug_log(DBG_SENSE, "EOP - %s\n",
+                               (readpos[0] & 0x40) ? "Yes" : "No");
+
+               if (readpos[0] & 0x4) {
+                       printk(KERN_INFO "ide-tape: Block location is unknown"
+                                        "to the tape\n");
+                       clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
+                       uptodate = 0;
+               } else {
+                       debug_log(DBG_SENSE, "Block Location - %u\n",
+                                       be32_to_cpu(*(u32 *)&readpos[4]));
+
+                       tape->partition = readpos[1];
+                       tape->first_frame = be32_to_cpu(*(u32 *)&readpos[4]);
+                       set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
+               }
        }
-       return ide_stopped;
+
+       idetape_end_request(drive, uptodate, 0);
+}
+
+static void idetape_init_pc(struct ide_atapi_pc *pc)
+{
+       memset(pc->c, 0, 12);
+       pc->retries = 0;
+       pc->flags = 0;
+       pc->req_xfer = 0;
+       pc->buf = pc->pc_buf;
+       pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
+       pc->bh = NULL;
+       pc->b_data = NULL;
+       pc->callback = ide_tape_callback;
 }
 
 static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
@@ -654,7 +696,6 @@ static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
        pc->c[0] = REQUEST_SENSE;
        pc->c[4] = 20;
        pc->req_xfer = 20;
-       pc->idetape_callback = &idetape_request_sense_callback;
 }
 
 static void idetape_init_rq(struct request *rq, u8 cmd)
@@ -696,7 +737,7 @@ static void idetape_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
  *     last packet command. We queue a request sense packet command in
  *     the head of the request list.
  */
-static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
+static void idetape_retry_pc(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc *pc;
@@ -708,7 +749,6 @@ static ide_startstop_t idetape_retry_pc (ide_drive_t *drive)
        idetape_create_request_sense_cmd(pc);
        set_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags);
        idetape_queue_pc_head(drive, pc, rq);
-       return ide_stopped;
 }
 
 /*
@@ -776,15 +816,16 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
                        debug_log(DBG_ERR, "%s: I/O error\n", tape->name);
 
                        if (pc->c[0] == REQUEST_SENSE) {
-                               printk(KERN_ERR "ide-tape: I/O error in request"
-                                               " sense command\n");
+                               printk(KERN_ERR "%s: I/O error in request sense"
+                                               " command\n", drive->name);
                                return ide_do_reset(drive);
                        }
                        debug_log(DBG_ERR, "[cmd %x]: check condition\n",
                                        pc->c[0]);
 
                        /* Retry operation */
-                       return idetape_retry_pc(drive);
+                       idetape_retry_pc(drive);
+                       return ide_stopped;
                }
                pc->error = 0;
                if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
@@ -800,13 +841,14 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
                if (tape->failed_pc == pc)
                        tape->failed_pc = NULL;
                /* Command finished - Call the callback function */
-               return pc->idetape_callback(drive);
+               pc->callback(drive);
+               return ide_stopped;
        }
 
        if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
                pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-               printk(KERN_ERR "ide-tape: The tape wants to issue more "
-                               "interrupts in DMA mode\n");
+               printk(KERN_ERR "%s: The device wants to issue more interrupts "
+                               "in DMA mode\n", drive->name);
                ide_dma_off(drive);
                return ide_do_reset(drive);
        }
@@ -817,14 +859,14 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
        ireason = hwif->INB(hwif->io_ports.nsect_addr);
 
        if (ireason & CD) {
-               printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__);
+               printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
                return ide_do_reset(drive);
        }
        if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) {
                /* Hopefully, we will never get here */
-               printk(KERN_ERR "ide-tape: We wanted to %s, ",
-                               (ireason & IO) ? "Write" : "Read");
-               printk(KERN_ERR "ide-tape: but the tape wants us to %s !\n",
+               printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
+                               "to %s!\n", drive->name,
+                               (ireason & IO) ? "Write" : "Read",
                                (ireason & IO) ? "Read" : "Write");
                return ide_do_reset(drive);
        }
@@ -833,15 +875,16 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
                temp = pc->xferred + bcount;
                if (temp > pc->req_xfer) {
                        if (temp > pc->buf_size) {
-                               printk(KERN_ERR "ide-tape: The tape wants to "
-                                       "send us more data than expected "
-                                       "- discarding data\n");
+                               printk(KERN_ERR "%s: The device wants to send "
+                                               "us more data than expected - "
+                                               "discarding data\n",
+                                               drive->name);
                                ide_pad_transfer(drive, 0, bcount);
                                ide_set_handler(drive, &idetape_pc_intr,
                                                IDETAPE_WAIT_CMD, NULL);
                                return ide_started;
                        }
-                       debug_log(DBG_SENSE, "The tape wants to send us more "
+                       debug_log(DBG_SENSE, "The device wants to send us more "
                                "data than expected - allowing transfer\n");
                }
                iobuf = &idetape_input_buffers;
@@ -914,26 +957,27 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
        u8 ireason;
 
        if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
-               printk(KERN_ERR "ide-tape: Strange, packet command initiated "
-                               "yet DRQ isn't asserted\n");
+               printk(KERN_ERR "%s: Strange, packet command initiated yet "
+                               "DRQ isn't asserted\n", drive->name);
                return startstop;
        }
        ireason = hwif->INB(hwif->io_ports.nsect_addr);
        while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) {
-               printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing "
-                               "a packet command, retrying\n");
+               printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
+                               "a packet command, retrying\n", drive->name);
                udelay(100);
                ireason = hwif->INB(hwif->io_ports.nsect_addr);
                if (retries == 0) {
-                       printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while "
-                                       "issuing a packet command, ignoring\n");
+                       printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
+                                       "a packet command, ignoring\n",
+                                       drive->name);
                        ireason |= CD;
                        ireason &= ~IO;
                }
        }
        if ((ireason & CD) == 0 || (ireason & IO)) {
-               printk(KERN_ERR "ide-tape: (IO,CoD) != (0,1) while issuing "
-                               "a packet command\n");
+               printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
+                               "a packet command\n", drive->name);
                return ide_do_reset(drive);
        }
        /* Set the interrupt routine */
@@ -990,7 +1034,8 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
                        pc->error = IDETAPE_ERROR_GENERAL;
                }
                tape->failed_pc = NULL;
-               return pc->idetape_callback(drive);
+               pc->callback(drive);
+               return ide_stopped;
        }
        debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
 
@@ -1005,7 +1050,7 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
                pc->flags &= ~PC_FLAG_DMA_ERROR;
                ide_dma_off(drive);
        }
-       if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma)
+       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma)
                dma_ok = !hwif->dma_ops->dma_setup(drive);
 
        ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_DEVICE, bcount, dma_ok);
@@ -1023,16 +1068,6 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
        }
 }
 
-static ide_startstop_t idetape_pc_callback(ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
-
-       idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
-       return ide_stopped;
-}
-
 /* A mode sense command is used to "sense" tape parameters. */
 static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
 {
@@ -1058,7 +1093,6 @@ static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
                pc->req_xfer = 24;
        else
                pc->req_xfer = 50;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
@@ -1076,7 +1110,8 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
                                printk(KERN_ERR "ide-tape: %s: I/O error, ",
                                                tape->name);
                        /* Retry operation */
-                       return idetape_retry_pc(drive);
+                       idetape_retry_pc(drive);
+                       return ide_stopped;
                }
                pc->error = 0;
                if (tape->failed_pc == pc)
@@ -1085,32 +1120,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
                pc->error = IDETAPE_ERROR_GENERAL;
                tape->failed_pc = NULL;
        }
-       return pc->idetape_callback(drive);
-}
-
-static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-       struct request *rq = HWGROUP(drive)->rq;
-       int blocks = tape->pc->xferred / tape->blk_size;
-
-       tape->avg_size += blocks * tape->blk_size;
-
-       if (time_after_eq(jiffies, tape->avg_time + HZ)) {
-               tape->avg_speed = tape->avg_size * HZ /
-                               (jiffies - tape->avg_time) / 1024;
-               tape->avg_size = 0;
-               tape->avg_time = jiffies;
-       }
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
-
-       tape->first_frame += blocks;
-       rq->current_nr_sectors -= blocks;
-
-       if (!tape->pc->error)
-               idetape_end_request(drive, 1, 0);
-       else
-               idetape_end_request(drive, tape->pc->error, 0);
+       pc->callback(drive);
        return ide_stopped;
 }
 
@@ -1122,14 +1132,13 @@ static void idetape_create_read_cmd(idetape_tape_t *tape,
        pc->c[0] = READ_6;
        put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
-       pc->idetape_callback = &idetape_rw_callback;
        pc->bh = bh;
        atomic_set(&bh->b_count, 0);
        pc->buf = NULL;
        pc->buf_size = length * tape->blk_size;
        pc->req_xfer = pc->buf_size;
        if (pc->req_xfer == tape->buffer_size)
-               pc->flags |= PC_FLAG_DMA_RECOMMENDED;
+               pc->flags |= PC_FLAG_DMA_OK;
 }
 
 static void idetape_create_write_cmd(idetape_tape_t *tape,
@@ -1140,7 +1149,6 @@ static void idetape_create_write_cmd(idetape_tape_t *tape,
        pc->c[0] = WRITE_6;
        put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
-       pc->idetape_callback = &idetape_rw_callback;
        pc->flags |= PC_FLAG_WRITING;
        pc->bh = bh;
        pc->b_data = bh->b_data;
@@ -1149,7 +1157,7 @@ static void idetape_create_write_cmd(idetape_tape_t *tape,
        pc->buf_size = length * tape->blk_size;
        pc->req_xfer = pc->buf_size;
        if (pc->req_xfer == tape->buffer_size)
-               pc->flags |= PC_FLAG_DMA_RECOMMENDED;
+               pc->flags |= PC_FLAG_DMA_OK;
 }
 
 static ide_startstop_t idetape_do_request(ide_drive_t *drive,
@@ -1409,40 +1417,6 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
        }
 }
 
-static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-       u8 *readpos = tape->pc->buf;
-
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
-
-       if (!tape->pc->error) {
-               debug_log(DBG_SENSE, "BOP - %s\n",
-                               (readpos[0] & 0x80) ? "Yes" : "No");
-               debug_log(DBG_SENSE, "EOP - %s\n",
-                               (readpos[0] & 0x40) ? "Yes" : "No");
-
-               if (readpos[0] & 0x4) {
-                       printk(KERN_INFO "ide-tape: Block location is unknown"
-                                        "to the tape\n");
-                       clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
-                       idetape_end_request(drive, 0, 0);
-               } else {
-                       debug_log(DBG_SENSE, "Block Location - %u\n",
-                                       be32_to_cpu(*(u32 *)&readpos[4]));
-
-                       tape->partition = readpos[1];
-                       tape->first_frame =
-                               be32_to_cpu(*(u32 *)&readpos[4]);
-                       set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
-                       idetape_end_request(drive, 1, 0);
-               }
-       } else {
-               idetape_end_request(drive, 0, 0);
-       }
-       return ide_stopped;
-}
-
 /*
  * Write a filemark if write_filemark=1. Flush the device buffers without
  * writing a filemark otherwise.
@@ -1454,14 +1428,12 @@ static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
        pc->c[0] = WRITE_FILEMARKS;
        pc->c[4] = write_filemark;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
 {
        idetape_init_pc(pc);
        pc->c[0] = TEST_UNIT_READY;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 /*
@@ -1499,7 +1471,6 @@ static void idetape_create_load_unload_cmd(ide_drive_t *drive,
        pc->c[0] = START_STOP;
        pc->c[4] = cmd;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
@@ -1551,7 +1522,6 @@ static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
        idetape_init_pc(pc);
        pc->c[0] = READ_POSITION;
        pc->req_xfer = 20;
-       pc->idetape_callback = &idetape_read_position_callback;
 }
 
 static int idetape_read_position(ide_drive_t *drive)
@@ -1579,7 +1549,6 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
        put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
        pc->c[8] = partition;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static int idetape_create_prevent_cmd(ide_drive_t *drive,
@@ -1594,7 +1563,6 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
        idetape_init_pc(pc);
        pc->c[0] = ALLOW_MEDIUM_REMOVAL;
        pc->c[4] = prevent;
-       pc->idetape_callback = &idetape_pc_callback;
        return 1;
 }
 
@@ -1701,7 +1669,6 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
        pc->c[0] = INQUIRY;
        pc->c[4] = 254;
        pc->req_xfer = 254;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static void idetape_create_rewind_cmd(ide_drive_t *drive,
@@ -1710,7 +1677,6 @@ static void idetape_create_rewind_cmd(ide_drive_t *drive,
        idetape_init_pc(pc);
        pc->c[0] = REZERO_UNIT;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
@@ -1719,7 +1685,6 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
        pc->c[0] = ERASE;
        pc->c[1] = 1;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
@@ -1729,7 +1694,6 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
        put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
        pc->c[1] = cmd;
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
-       pc->idetape_callback = &idetape_pc_callback;
 }
 
 /* Queue up a character device originated write request. */