include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / ide / ide-floppy.c
index fb23564..4713bdc 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/major.h>
 #include <linux/errno.h>
 #include <linux/genhd.h>
-#include <linux/slab.h>
 #include <linux/cdrom.h>
 #include <linux/ide.h>
 #include <linux/hdreg.h>
  */
 #define IDEFLOPPY_PC_DELAY     (HZ/20) /* default delay for ZIP 100 (50ms) */
 
-/*
- * 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 request *rq = drive->hwif->rq;
-       int error;
-
-       ide_debug_log(IDE_DBG_FUNC, "enter");
-
-       switch (uptodate) {
-       case 0:
-               error = IDE_DRV_ERROR_GENERAL;
-               break;
-
-       case 1:
-               error = 0;
-               break;
-
-       default:
-               error = uptodate;
-       }
-
-       if (error)
-               drive->failed_pc = NULL;
-
-       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_complete_rq(drive, 0);
-       return 0;
-}
-
-static void idefloppy_update_buffers(ide_drive_t *drive,
-                               struct ide_atapi_pc *pc)
-{
-       struct request *rq = pc->rq;
-       struct bio *bio = rq->bio;
-
-       while ((bio = rq->bio) != NULL)
-               ide_floppy_end_request(drive, 1, 0);
-}
-
-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");
@@ -121,10 +73,11 @@ static void ide_floppy_callback(ide_drive_t *drive, int dsc)
                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;
+
+               u8 *buf = bio_data(rq->bio);
 
                if (!pc->error) {
                        floppy->sense_key = buf[2] & 0x0F;
@@ -145,7 +98,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,
@@ -164,8 +120,9 @@ 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;
 
@@ -177,13 +134,17 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
        drive->pc = pc;
 
        if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
+               unsigned int done = blk_rq_bytes(drive->hwif->rq);
+
                if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
                        ide_floppy_report_error(floppy, pc);
+
                /* Giving up */
                pc->error = IDE_DRV_ERROR_GENERAL;
 
                drive->failed_pc = NULL;
                drive->pc_callback(drive, 0);
+               ide_complete_rq(drive, -EIO, done);
                return ide_stopped;
        }
 
@@ -191,7 +152,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)
@@ -233,7 +194,7 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
 {
        struct ide_disk_obj *floppy = drive->driver_data;
        int block = sector / floppy->bs_factor;
-       int blocks = rq->nr_sectors / floppy->bs_factor;
+       int blocks = blk_rq_sectors(rq) / floppy->bs_factor;
        int cmd = rq_data_dir(rq);
 
        ide_debug_log(IDE_DBG_FUNC, "block: %d, blocks: %d", block, blocks);
@@ -246,11 +207,9 @@ static void idefloppy_create_rw_cmd(ide_drive_t *drive,
        memcpy(rq->cmd, pc->c, 12);
 
        pc->rq = rq;
-       pc->b_count = 0;
        if (rq->cmd_flags & REQ_RW)
                pc->flags |= PC_FLAG_WRITING;
-       pc->buf = NULL;
-       pc->req_xfer = pc->buf_size = blocks * floppy->block_size;
+
        pc->flags |= PC_FLAG_DMA_OK;
 }
 
@@ -260,72 +219,81 @@ static void idefloppy_blockpc_cmd(struct ide_disk_obj *floppy,
        ide_init_pc(pc);
        memcpy(pc->c, rq->cmd, sizeof(pc->c));
        pc->rq = rq;
-       pc->b_count = 0;
-       if (rq->data_len && rq_data_dir(rq) == WRITE)
-               pc->flags |= PC_FLAG_WRITING;
-       pc->buf = rq->data;
-       if (rq->bio)
+       if (blk_rq_bytes(rq)) {
                pc->flags |= PC_FLAG_DMA_OK;
-       /*
-        * possibly problematic, doesn't look like ide-floppy correctly
-        * handled scattered requests if dma fails...
-        */
-       pc->req_xfer = pc->buf_size = rq->data_len;
+               if (rq_data_dir(rq) == WRITE)
+                       pc->flags |= PC_FLAG_WRITING;
+       }
 }
 
 static ide_startstop_t ide_floppy_do_request(ide_drive_t *drive,
                                             struct request *rq, sector_t block)
 {
        struct ide_disk_obj *floppy = drive->driver_data;
-       ide_hwif_t *hwif = drive->hwif;
+       struct ide_cmd cmd;
        struct ide_atapi_pc *pc;
 
+       ide_debug_log(IDE_DBG_FUNC, "enter, cmd: 0x%x\n", rq->cmd[0]);
+
        if (drive->debug_mask & IDE_DBG_RQ)
                blk_dump_rq_flags(rq, (rq->rq_disk
                                        ? rq->rq_disk->disk_name
                                        : "dev?"));
 
        if (rq->errors >= ERROR_MAX) {
-               if (drive->failed_pc)
+               if (drive->failed_pc) {
                        ide_floppy_report_error(floppy, drive->failed_pc);
-               else
+                       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)) {
+               if (((long)blk_rq_pos(rq) % floppy->bs_factor) ||
+                   (blk_rq_sectors(rq) % 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);
-       } else if (blk_special_request(rq)) {
-               pc = (struct ide_atapi_pc *) rq->buffer;
+       } else if (blk_special_request(rq) || blk_sense_request(rq)) {
+               pc = (struct ide_atapi_pc *)rq->special;
        } else if (blk_pc_request(rq)) {
                pc = &floppy->queued_pc;
                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;
-       }
+       } else
+               BUG();
 
-       if (blk_fs_request(rq) || pc->req_xfer) {
-               ide_init_sg_cmd(drive, rq);
-               ide_map_sg(drive, rq);
-       }
+       ide_prep_sense(drive, rq);
 
-       pc->sg = hwif->sg_table;
-       pc->sg_cnt = hwif->sg_nents;
+       memset(&cmd, 0, sizeof(cmd));
+
+       if (rq_data_dir(rq))
+               cmd.tf_flags |= IDE_TFLAG_WRITE;
+
+       cmd.rq = rq;
+
+       if (blk_fs_request(rq) || blk_rq_bytes(rq)) {
+               ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
+               ide_map_sg(drive, &cmd);
+       }
 
        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, blk_rq_bytes(rq));
+       return ide_stopped;
 }
 
 /*
@@ -337,33 +305,33 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive,
 {
        struct ide_disk_obj *floppy = drive->driver_data;
        struct gendisk *disk = floppy->disk;
-       u8 *page;
+       u8 *page, buf[40];
        int capacity, lba_capacity;
        u16 transfer_rate, sector_size, cyls, rpm;
        u8 heads, sectors;
 
        ide_floppy_create_mode_sense_cmd(pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
 
-       if (ide_queue_pc_tail(drive, disk, pc)) {
+       if (ide_queue_pc_tail(drive, disk, pc, buf, pc->req_xfer)) {
                printk(KERN_ERR PFX "Can't get flexible disk page params\n");
                return 1;
        }
 
-       if (pc->buf[3] & 0x80)
+       if (buf[3] & 0x80)
                drive->dev_flags |= IDE_DFLAG_WP;
        else
                drive->dev_flags &= ~IDE_DFLAG_WP;
 
        set_disk_ro(disk, !!(drive->dev_flags & IDE_DFLAG_WP));
 
-       page = &pc->buf[8];
+       page = &buf[8];
 
-       transfer_rate = be16_to_cpup((__be16 *)&pc->buf[8 + 2]);
-       sector_size   = be16_to_cpup((__be16 *)&pc->buf[8 + 6]);
-       cyls          = be16_to_cpup((__be16 *)&pc->buf[8 + 8]);
-       rpm           = be16_to_cpup((__be16 *)&pc->buf[8 + 28]);
-       heads         = pc->buf[8 + 4];
-       sectors       = pc->buf[8 + 5];
+       transfer_rate = be16_to_cpup((__be16 *)&buf[8 + 2]);
+       sector_size   = be16_to_cpup((__be16 *)&buf[8 + 6]);
+       cyls          = be16_to_cpup((__be16 *)&buf[8 + 8]);
+       rpm           = be16_to_cpup((__be16 *)&buf[8 + 28]);
+       heads         = buf[8 + 4];
+       sectors       = buf[8 + 5];
 
        capacity = cyls * heads * sectors * sector_size;
 
@@ -401,9 +369,11 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        struct gendisk *disk = floppy->disk;
        struct ide_atapi_pc pc;
        u8 *cap_desc;
-       u8 header_len, desc_cnt;
+       u8 pc_buf[256], header_len, desc_cnt;
        int i, rc = 1, blocks, length;
 
+       ide_debug_log(IDE_DBG_FUNC, "enter");
+
        drive->bios_cyl = 0;
        drive->bios_head = drive->bios_sect = 0;
        floppy->blocks = 0;
@@ -411,19 +381,19 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        drive->capacity64 = 0;
 
        ide_floppy_create_read_capacity_cmd(&pc);
-       if (ide_queue_pc_tail(drive, disk, &pc)) {
+       if (ide_queue_pc_tail(drive, disk, &pc, pc_buf, pc.req_xfer)) {
                printk(KERN_ERR PFX "Can't get floppy parameters\n");
                return 1;
        }
-       header_len = pc.buf[3];
-       cap_desc = &pc.buf[4];
+       header_len = pc_buf[3];
+       cap_desc = &pc_buf[4];
        desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */
 
        for (i = 0; i < desc_cnt; i++) {
                unsigned int desc_start = 4 + i*8;
 
-               blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
-               length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
+               blocks = be32_to_cpup((__be32 *)&pc_buf[desc_start]);
+               length = be16_to_cpup((__be16 *)&pc_buf[desc_start + 6]);
 
                ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
                                             "%d sector size",
@@ -436,7 +406,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                 * the code below is valid only for the 1st descriptor, ie i=0
                 */
 
-               switch (pc.buf[desc_start + 4] & 0x03) {
+               switch (pc_buf[desc_start + 4] & 0x03) {
                /* Clik! drive returns this instead of CAPACITY_CURRENT */
                case CAPACITY_UNFORMATTED:
                        if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
@@ -485,7 +455,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                        break;
                }
                ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d",
-                                            pc.buf[desc_start + 4] & 0x03);
+                                            pc_buf[desc_start + 4] & 0x03);
        }
 
        /* Clik! disk does not support get_flexible_disk_page */
@@ -501,8 +471,6 @@ static void ide_floppy_setup(ide_drive_t *drive)
        u16 *id = drive->id;
 
        drive->pc_callback       = ide_floppy_callback;
-       drive->pc_update_buffers = idefloppy_update_buffers;
-       drive->pc_io_buffers     = ide_io_buffers;
 
        /*
         * We used to check revisions here. At this point however I'm giving up.
@@ -517,7 +485,7 @@ static void ide_floppy_setup(ide_drive_t *drive)
                drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
                /* This value will be visible in the /proc/ide/hdx/settings */
                drive->pc_delay = IDEFLOPPY_PC_DELAY;
-               blk_queue_max_sectors(drive->queue, 64);
+               blk_queue_max_hw_sectors(drive->queue, 64);
        }
 
        /*
@@ -525,7 +493,7 @@ static void ide_floppy_setup(ide_drive_t *drive)
         * nasty clicking noises without it, so please don't remove this.
         */
        if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) {
-               blk_queue_max_sectors(drive->queue, 64);
+               blk_queue_max_hw_sectors(drive->queue, 64);
                drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
                /* IOMEGA Clik! drives do not support lock/unlock commands */
                drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
@@ -564,6 +532,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,
 };