]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-floppy.c
Merge branch 'bkl-removal' of git://git.lwn.net/linux-2.6
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-floppy.c
index d1a79e8e0d69b931434709bf3a6cabf3cede8e5c..7ae66233483519ac52cc0921f0b2c61229c6153c 100644 (file)
  */
 #define IDEFLOPPY_PC_DELAY     (HZ/20) /* default delay for ZIP 100 (50ms) */
 
-/* Error code returned in rq->errors to the higher part of the driver. */
-#define        IDEFLOPPY_ERROR_GENERAL         101
-
-/*
- * Used to finish servicing a request. For read/write requests, we will call
- * ide_end_request to pass to the next buffer.
- */
-static int ide_floppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
-{
-       struct ide_disk_obj *floppy = drive->driver_data;
-       struct request *rq = drive->hwif->rq;
-       int error;
-
-       ide_debug_log(IDE_DBG_FUNC, "enter");
-
-       switch (uptodate) {
-       case 0:
-               error = IDEFLOPPY_ERROR_GENERAL;
-               break;
-
-       case 1:
-               error = 0;
-               break;
-
-       default:
-               error = uptodate;
-       }
-
-       if (error)
-               floppy->failed_pc = NULL;
-       /* Why does this happen? */
-       if (!rq)
-               return 0;
-       if (!blk_special_request(rq)) {
-               /* our real local end request function */
-               ide_end_request(drive, uptodate, nsecs);
-               return 0;
-       }
-       rq->errors = error;
-       /* fixme: need to move this local also */
-       ide_end_drive_cmd(drive, 0, 0);
-       return 0;
-}
-
 static void idefloppy_update_buffers(ide_drive_t *drive,
                                struct ide_atapi_pc *pc)
 {
@@ -112,22 +68,23 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
        struct bio *bio = rq->bio;
 
        while ((bio = rq->bio) != NULL)
-               ide_floppy_end_request(drive, 1, 0);
+               ide_complete_rq(drive, 0, ide_rq_bytes(rq));
 }
 
-static void ide_floppy_callback(ide_drive_t *drive, int dsc)
+static int ide_floppy_callback(ide_drive_t *drive, int dsc)
 {
        struct ide_disk_obj *floppy = drive->driver_data;
        struct ide_atapi_pc *pc = drive->pc;
+       struct request *rq = pc->rq;
        int uptodate = pc->error ? 0 : 1;
 
        ide_debug_log(IDE_DBG_FUNC, "enter");
 
-       if (floppy->failed_pc == pc)
-               floppy->failed_pc = NULL;
+       if (drive->failed_pc == pc)
+               drive->failed_pc = NULL;
 
        if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
-           (pc->rq && blk_pc_request(pc->rq)))
+           (rq && blk_pc_request(rq)))
                uptodate = 1; /* FIXME */
        else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
                u8 *buf = pc->buf;
@@ -139,9 +96,9 @@ static void ide_floppy_callback(ide_drive_t *drive, int dsc)
                        floppy->progress_indication = buf[15] & 0x80 ?
                                (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
 
-                       if (floppy->failed_pc)
+                       if (drive->failed_pc)
                                ide_debug_log(IDE_DBG_PC, "pc = %x",
-                                             floppy->failed_pc->c[0]);
+                                             drive->failed_pc->c[0]);
 
                        ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
                                      "ascq = %x", floppy->sense_key,
@@ -151,7 +108,10 @@ static void ide_floppy_callback(ide_drive_t *drive, int dsc)
                               "Aborting request!\n");
        }
 
-       ide_floppy_end_request(drive, uptodate, 0);
+       if (blk_special_request(rq))
+               rq->errors = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
+
+       return uptodate;
 }
 
 static void ide_floppy_report_error(struct ide_disk_obj *floppy,
@@ -170,14 +130,15 @@ static void ide_floppy_report_error(struct ide_disk_obj *floppy,
 
 }
 
-static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
-               struct ide_atapi_pc *pc)
+static ide_startstop_t ide_floppy_issue_pc(ide_drive_t *drive,
+                                          struct ide_cmd *cmd,
+                                          struct ide_atapi_pc *pc)
 {
        struct ide_disk_obj *floppy = drive->driver_data;
 
-       if (floppy->failed_pc == NULL &&
+       if (drive->failed_pc == NULL &&
            pc->c[0] != GPCMD_REQUEST_SENSE)
-               floppy->failed_pc = pc;
+               drive->failed_pc = pc;
 
        /* Set the current packet command */
        drive->pc = pc;
@@ -186,9 +147,9 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
                if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
                        ide_floppy_report_error(floppy, pc);
                /* Giving up */
-               pc->error = IDEFLOPPY_ERROR_GENERAL;
+               pc->error = IDE_DRV_ERROR_GENERAL;
 
-               floppy->failed_pc = NULL;
+               drive->failed_pc = NULL;
                drive->pc_callback(drive, 0);
                return ide_stopped;
        }
@@ -197,7 +158,7 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
 
        pc->retries++;
 
-       return ide_issue_pc(drive);
+       return ide_issue_pc(drive, cmd);
 }
 
 void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -284,6 +245,7 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
 {
        struct ide_disk_obj *floppy = drive->driver_data;
        ide_hwif_t *hwif = drive->hwif;
+       struct ide_cmd cmd;
        struct ide_atapi_pc *pc;
 
        if (drive->debug_mask & IDE_DBG_RQ)
@@ -292,21 +254,25 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
                                        : "dev?"));
 
        if (rq->errors >= ERROR_MAX) {
-               if (floppy->failed_pc)
-                       ide_floppy_report_error(floppy, floppy->failed_pc);
-               else
+               if (drive->failed_pc) {
+                       ide_floppy_report_error(floppy, drive->failed_pc);
+                       drive->failed_pc = NULL;
+               } else
                        printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
 
-               ide_floppy_end_request(drive, 0, 0);
-               return ide_stopped;
+               if (blk_special_request(rq)) {
+                       rq->errors = 0;
+                       ide_complete_rq(drive, 0, blk_rq_bytes(rq));
+                       return ide_stopped;
+               } else
+                       goto out_end;
        }
        if (blk_fs_request(rq)) {
                if (((long)rq->sector % floppy->bs_factor) ||
                    (rq->nr_sectors % floppy->bs_factor)) {
                        printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
                                drive->name);
-                       ide_floppy_end_request(drive, 0, 0);
-                       return ide_stopped;
+                       goto out_end;
                }
                pc = &floppy->queued_pc;
                idefloppy_create_rw_cmd(drive, pc, rq, (unsigned long)block);
@@ -317,21 +283,33 @@ static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
                idefloppy_blockpc_cmd(floppy, pc, rq);
        } else {
                blk_dump_rq_flags(rq, PFX "unsupported command in queue");
-               ide_floppy_end_request(drive, 0, 0);
-               return ide_stopped;
+               goto out_end;
        }
 
+       memset(&cmd, 0, sizeof(cmd));
+
+       if (rq_data_dir(rq))
+               cmd.tf_flags |= IDE_TFLAG_WRITE;
+
+       cmd.rq = rq;
+
        if (blk_fs_request(rq) || pc->req_xfer) {
-               ide_init_sg_cmd(drive, rq);
-               ide_map_sg(drive, rq);
+               ide_init_sg_cmd(&cmd, rq->nr_sectors << 9);
+               ide_map_sg(drive, &cmd);
        }
 
        pc->sg = hwif->sg_table;
-       pc->sg_cnt = hwif->sg_nents;
+       pc->sg_cnt = cmd.sg_nents;
 
        pc->rq = rq;
 
-       return idefloppy_issue_pc(drive, pc);
+       return ide_floppy_issue_pc(drive, &cmd, pc);
+out_end:
+       drive->failed_pc = NULL;
+       if (blk_fs_request(rq) == 0 && rq->errors == 0)
+               rq->errors = -EIO;
+       ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
+       return ide_stopped;
 }
 
 /*
@@ -570,6 +548,5 @@ const struct ide_disk_ops ide_atapi_disk_ops = {
        .init_media     = ide_floppy_init_media,
        .set_doorlock   = ide_set_media_lock,
        .do_request     = ide_floppy_do_request,
-       .end_request    = ide_floppy_end_request,
        .ioctl          = ide_floppy_ioctl,
 };