Merge commit 'upstream/master'
[pandora-kernel.git] / drivers / ide / ide-floppy.c
index 1df6a31..ca11a26 100644 (file)
@@ -125,26 +125,10 @@ typedef struct ide_floppy_obj {
        int wp;
        /* Supports format progress report */
        int srfp;
-       /* Status/Action flags */
-       unsigned long flags;
 } idefloppy_floppy_t;
 
 #define IDEFLOPPY_TICKS_DELAY  HZ/20   /* default delay for ZIP 100 (50ms) */
 
-/* Floppy flag bits values. */
-enum {
-       /* DRQ interrupt device */
-       IDEFLOPPY_FLAG_DRQ_INTERRUPT            = (1 << 0),
-       /* Media may have changed */
-       IDEFLOPPY_FLAG_MEDIA_CHANGED            = (1 << 1),
-       /* Format in progress */
-       IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS       = (1 << 2),
-       /* Avoid commands not supported in Clik drive */
-       IDEFLOPPY_FLAG_CLIK_DRIVE               = (1 << 3),
-       /* Requires BH algorithm for packets */
-       IDEFLOPPY_FLAG_ZIP_DRIVE                = (1 << 4),
-};
-
 /* Defines for the MODE SENSE command */
 #define MODE_SENSE_CURRENT             0x00
 #define MODE_SENSE_CHANGEABLE          0x01
@@ -174,23 +158,29 @@ static DEFINE_MUTEX(idefloppy_ref_mutex);
 #define ide_floppy_g(disk) \
        container_of((disk)->private_data, struct ide_floppy_obj, driver)
 
+static void idefloppy_cleanup_obj(struct kref *);
+
 static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
 {
        struct ide_floppy_obj *floppy = NULL;
 
        mutex_lock(&idefloppy_ref_mutex);
        floppy = ide_floppy_g(disk);
-       if (floppy)
+       if (floppy) {
                kref_get(&floppy->kref);
+               if (ide_device_get(floppy->drive)) {
+                       kref_put(&floppy->kref, idefloppy_cleanup_obj);
+                       floppy = NULL;
+               }
+       }
        mutex_unlock(&idefloppy_ref_mutex);
        return floppy;
 }
 
-static void idefloppy_cleanup_obj(struct kref *);
-
 static void ide_floppy_put(struct ide_floppy_obj *floppy)
 {
        mutex_lock(&idefloppy_ref_mutex);
+       ide_device_put(floppy->drive);
        kref_put(&floppy->kref, idefloppy_cleanup_obj);
        mutex_unlock(&idefloppy_ref_mutex);
 }
@@ -247,9 +237,9 @@ static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
 
                data = bvec_kmap_irq(bvec, &flags);
                if (direction)
-                       hwif->output_data(drive, NULL, data, count);
+                       hwif->tp_ops->output_data(drive, NULL, data, count);
                else
-                       hwif->input_data(drive, NULL, data, count);
+                       hwif->tp_ops->input_data(drive, NULL, data, count);
                bvec_kunmap_irq(data, &flags);
 
                bcount -= count;
@@ -291,6 +281,7 @@ static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
        rq->cmd_type = REQ_TYPE_SPECIAL;
        rq->cmd_flags |= REQ_PREEMPT;
        rq->rq_disk = floppy->disk;
+       memcpy(rq->cmd, pc->c, 12);
        ide_do_drive_cmd(drive, rq);
 }
 
@@ -320,6 +311,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
 
        debug_log("Reached %s\n", __func__);
 
+       if (floppy->failed_pc == pc)
+               floppy->failed_pc = NULL;
+
        if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 ||
            (pc->rq && blk_pc_request(pc->rq)))
                uptodate = 1; /* FIXME */
@@ -348,13 +342,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
 
 static void idefloppy_init_pc(struct ide_atapi_pc *pc)
 {
-       memset(pc->c, 0, 12);
-       pc->retries = 0;
-       pc->flags = 0;
-       pc->req_xfer = 0;
+       memset(pc, 0, sizeof(*pc));
        pc->buf = pc->pc_buf;
        pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
-       pc->callback = ide_floppy_callback;
 }
 
 static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
@@ -385,128 +375,10 @@ static void idefloppy_retry_pc(ide_drive_t *drive)
 static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
-       ide_hwif_t *hwif = drive->hwif;
-       struct ide_atapi_pc *pc = floppy->pc;
-       struct request *rq = pc->rq;
-       xfer_func_t *xferfunc;
-       unsigned int temp;
-       int dma_error = 0;
-       u16 bcount;
-       u8 stat, ireason;
-
-       debug_log("Reached %s interrupt handler\n", __func__);
-
-       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
-               dma_error = hwif->dma_ops->dma_end(drive);
-               if (dma_error) {
-                       printk(KERN_ERR "%s: DMA %s error\n", drive->name,
-                                       rq_data_dir(rq) ? "write" : "read");
-                       pc->flags |= PC_FLAG_DMA_ERROR;
-               } else {
-                       pc->xferred = pc->req_xfer;
-                       idefloppy_update_buffers(drive, pc);
-               }
-               debug_log("DMA finished\n");
-       }
-
-       /* Clear the interrupt */
-       stat = ide_read_status(drive);
-
-       /* No more interrupts */
-       if ((stat & DRQ_STAT) == 0) {
-               debug_log("Packet command completed, %d bytes transferred\n",
-                               pc->xferred);
-               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-
-               local_irq_enable_in_hardirq();
-
-               if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) {
-                       /* Error detected */
-                       debug_log("%s: I/O error\n", drive->name);
-                       rq->errors++;
-                       if (pc->c[0] == GPCMD_REQUEST_SENSE) {
-                               printk(KERN_ERR "%s: I/O error in request sense"
-                                               " command\n", drive->name);
-                               return ide_do_reset(drive);
-                       }
-                       /* Retry operation */
-                       idefloppy_retry_pc(drive);
-                       /* queued, but not started */
-                       return ide_stopped;
-               }
-               pc->error = 0;
-               if (floppy->failed_pc == pc)
-                       floppy->failed_pc = NULL;
-               /* Command finished - Call the callback function */
-               pc->callback(drive);
-               return ide_stopped;
-       }
-
-       if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
-               pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-               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);
-       }
-
-       /* Get the number of bytes to transfer */
-       bcount = (hwif->INB(hwif->io_ports.lbah_addr) << 8) |
-                 hwif->INB(hwif->io_ports.lbam_addr);
-       /* on this interrupt */
-       ireason = hwif->INB(hwif->io_ports.nsect_addr);
-
-       if (ireason & CD) {
-               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 "%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);
-       }
-       if (!(pc->flags & PC_FLAG_WRITING)) {
-               /* Reading - Check that we have enough space */
-               temp = pc->xferred + bcount;
-               if (temp > pc->req_xfer) {
-                       if (temp > pc->buf_size) {
-                               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,
-                                               &idefloppy_pc_intr,
-                                               IDEFLOPPY_WAIT_CMD,
-                                               NULL);
-                               return ide_started;
-                       }
-                       debug_log("The device wants to send us more data than "
-                                 "expected - allowing transfer\n");
-               }
-       }
-       if (pc->flags & PC_FLAG_WRITING)
-               xferfunc = hwif->output_data;
-       else
-               xferfunc = hwif->input_data;
-
-       if (pc->buf)
-               xferfunc(drive, NULL, pc->cur_pos, bcount);
-       else
-               ide_floppy_io_buffers(drive, pc, bcount,
-                                     !!(pc->flags & PC_FLAG_WRITING));
-
-       /* Update the current position */
-       pc->xferred += bcount;
-       pc->cur_pos += bcount;
 
-       /* And set the interrupt handler again */
-       ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL);
-       return ide_started;
+       return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
+                          IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers,
+                          idefloppy_retry_pc, NULL, ide_floppy_io_buffers);
 }
 
 /*
@@ -514,43 +386,31 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
  * service routine. In interrupt mode, the device sends an interrupt to signal
  * that it is ready to receive a packet. However, we need to delay about 2-3
  * ticks before issuing the packet or we gets in trouble.
- *
- * So, follow carefully. transfer_pc1 is called as an interrupt (or directly).
- * In either case, when the device says it's ready for a packet, we schedule
- * the packet transfer to occur about 2-3 ticks later in transfer_pc2.
  */
-static int idefloppy_transfer_pc2(ide_drive_t *drive)
+static int idefloppy_transfer_pc(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
 
        /* Send the actual packet */
-       drive->hwif->output_data(drive, NULL, floppy->pc->c, 12);
+       drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
 
        /* Timeout for the packet command */
        return IDEFLOPPY_WAIT_CMD;
 }
 
-static ide_startstop_t idefloppy_transfer_pc1(ide_drive_t *drive)
+
+/*
+ * Called as an interrupt (or directly). When the device says it's ready for a
+ * packet, we schedule the packet transfer to occur about 2-3 ticks later in
+ * transfer_pc.
+ */
+static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = drive->hwif;
        idefloppy_floppy_t *floppy = drive->driver_data;
        struct ide_atapi_pc *pc = floppy->pc;
        ide_expiry_t *expiry;
        unsigned int timeout;
-       ide_startstop_t startstop;
-       u8 ireason;
 
-       if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) {
-               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);
-       if ((ireason & CD) == 0 || (ireason & IO)) {
-               printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
-                               "a packet command\n", drive->name);
-               return ide_do_reset(drive);
-       }
        /*
         * The following delay solves a problem with ATAPI Zip 100 drives
         * where the Busy flag was apparently being deasserted before the
@@ -559,27 +419,15 @@ static ide_startstop_t idefloppy_transfer_pc1(ide_drive_t *drive)
         * 40 and 50msec work well. idefloppy_pc_intr will not be actually
         * used until after the packet is moved in about 50 msec.
         */
-       if (floppy->flags & IDEFLOPPY_FLAG_ZIP_DRIVE) {
+       if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
                timeout = floppy->ticks;
-               expiry = &idefloppy_transfer_pc2;
+               expiry = &idefloppy_transfer_pc;
        } else {
                timeout = IDEFLOPPY_WAIT_CMD;
                expiry = NULL;
        }
 
-       ide_set_handler(drive, &idefloppy_pc_intr, timeout, expiry);
-
-       /* Begin DMA, if necessary */
-       if (pc->flags & PC_FLAG_DMA_OK) {
-               pc->flags |= PC_FLAG_DMA_IN_PROGRESS;
-               hwif->dma_ops->dma_start(drive);
-       }
-
-       if ((floppy->flags & IDEFLOPPY_FLAG_ZIP_DRIVE) == 0)
-               /* Send the actual packet */
-               hwif->output_data(drive, NULL, floppy->pc->c, 12);
-
-       return ide_started;
+       return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
 }
 
 static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
@@ -602,9 +450,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)
@@ -619,44 +464,16 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
                pc->error = IDEFLOPPY_ERROR_GENERAL;
 
                floppy->failed_pc = NULL;
-               pc->callback(drive);
+               drive->pc_callback(drive);
                return ide_stopped;
        }
 
        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 (floppy->flags & IDEFLOPPY_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_start_pc_transfer,
+                           IDEFLOPPY_WAIT_CMD, NULL);
 }
 
 static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
@@ -731,12 +548,6 @@ static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
        pc->c[4] = start;
 }
 
-static void idefloppy_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
-{
-       idefloppy_init_pc(pc);
-       pc->c[0] = GPCMD_TEST_UNIT_READY;
-}
-
 static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
                                    struct ide_atapi_pc *pc, struct request *rq,
                                    unsigned long sector)
@@ -753,6 +564,8 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
        put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
        put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
 
+       memcpy(rq->cmd, pc->c, 12);
+
        pc->rq = rq;
        pc->b_count = cmd == READ ? 0 : rq->bio->bi_size;
        if (rq->cmd_flags & REQ_RW)
@@ -827,6 +640,7 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
        }
 
        pc->rq = rq;
+
        return idefloppy_issue_pc(drive, pc);
 }
 
@@ -843,6 +657,7 @@ static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
        rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
        rq->buffer = (char *) pc;
        rq->cmd_type = REQ_TYPE_SPECIAL;
+       memcpy(rq->cmd, pc->c, 12);
        error = blk_execute_rq(drive->queue, floppy->disk, rq, 0);
        blk_put_request(rq);
 
@@ -874,10 +689,10 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
        set_disk_ro(floppy->disk, floppy->wp);
        page = &pc.buf[8];
 
-       transfer_rate = be16_to_cpu(*(u16 *)&pc.buf[8 + 2]);
-       sector_size   = be16_to_cpu(*(u16 *)&pc.buf[8 + 6]);
-       cyls          = be16_to_cpu(*(u16 *)&pc.buf[8 + 8]);
-       rpm           = be16_to_cpu(*(u16 *)&pc.buf[8 + 28]);
+       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];
 
@@ -952,8 +767,8 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        for (i = 0; i < desc_cnt; i++) {
                unsigned int desc_start = 4 + i*8;
 
-               blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]);
-               length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]);
+               blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
+               length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
 
                debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
                                i, blocks * length / 1024, blocks, length);
@@ -967,7 +782,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                switch (pc.buf[desc_start + 4] & 0x03) {
                /* Clik! drive returns this instead of CAPACITY_CURRENT */
                case CAPACITY_UNFORMATTED:
-                       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
+                       if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
                                /*
                                 * If it is not a clik drive, break out
                                 * (maintains previous driver behaviour)
@@ -1013,7 +828,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        }
 
        /* Clik! disk does not support get_flexible_disk_page */
-       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE))
+       if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE))
                (void) ide_floppy_get_flexible_disk_page(drive);
 
        set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor);
@@ -1074,8 +889,8 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
                if (u_index >= u_array_size)
                        break;  /* User-supplied buffer too small */
 
-               blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]);
-               length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]);
+               blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
+               length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
 
                if (put_user(blocks, argp))
                        return(-EFAULT);
@@ -1121,11 +936,12 @@ static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg)
 
                /* Else assume format_unit has finished, and we're at 0x10000 */
        } else {
+               ide_hwif_t *hwif = drive->hwif;
                unsigned long flags;
                u8 stat;
 
                local_irq_save(flags);
-               stat = ide_read_status(drive);
+               stat = hwif->tp_ops->read_status(hwif);
                local_irq_restore(flags);
 
                progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000;
@@ -1211,9 +1027,10 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
 
        *((u16 *) &gcw) = drive->id->config;
        floppy->pc = floppy->pc_stack;
+       drive->pc_callback = ide_floppy_callback;
 
        if (((gcw[0] & 0x60) >> 5) == 1)
-               floppy->flags |= IDEFLOPPY_FLAG_DRQ_INTERRUPT;
+               drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
        /*
         * We used to check revisions here. At this point however I'm giving up.
         * Just assume they are all broken, its easier.
@@ -1224,7 +1041,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
         * we'll leave the limitation below for the 2.2.x tree.
         */
        if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) {
-               floppy->flags |= IDEFLOPPY_FLAG_ZIP_DRIVE;
+               drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
                /* This value will be visible in the /proc/ide/hdx/settings */
                floppy->ticks = IDEFLOPPY_TICKS_DELAY;
                blk_queue_max_sectors(drive->queue, 64);
@@ -1236,7 +1053,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
         */
        if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) {
                blk_queue_max_sectors(drive->queue, 64);
-               floppy->flags |= IDEFLOPPY_FLAG_CLIK_DRIVE;
+               drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE;
        }
 
        (void) ide_floppy_get_capacity(drive);
@@ -1301,7 +1118,6 @@ static ide_driver_t idefloppy_driver = {
        .do_request             = idefloppy_do_request,
        .end_request            = idefloppy_end_request,
        .error                  = __ide_error,
-       .abort                  = __ide_abort,
 #ifdef CONFIG_IDE_PROC_FS
        .proc                   = idefloppy_proc,
 #endif
@@ -1326,10 +1142,12 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
        floppy->openers++;
 
        if (floppy->openers == 1) {
-               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+               drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
                /* Just in case */
 
-               idefloppy_create_test_unit_ready_cmd(&pc);
+               idefloppy_init_pc(&pc);
+               pc.c[0] = GPCMD_TEST_UNIT_READY;
+
                if (idefloppy_queue_pc_tail(drive, &pc)) {
                        idefloppy_create_start_stop_cmd(&pc, 1);
                        (void) idefloppy_queue_pc_tail(drive, &pc);
@@ -1351,14 +1169,14 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
                        ret = -EROFS;
                        goto out_put_floppy;
                }
-               floppy->flags |= IDEFLOPPY_FLAG_MEDIA_CHANGED;
+               drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
                /* IOMEGA Clik! drives do not support lock/unlock commands */
-               if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
+               if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
                        idefloppy_create_prevent_cmd(&pc, 1);
                        (void) idefloppy_queue_pc_tail(drive, &pc);
                }
                check_disk_change(inode->i_bdev);
-       } else if (floppy->flags & IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS) {
+       } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
                ret = -EBUSY;
                goto out_put_floppy;
        }
@@ -1381,12 +1199,12 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
 
        if (floppy->openers == 1) {
                /* IOMEGA Clik! drives do not support lock/unlock commands */
-               if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
+               if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
                        idefloppy_create_prevent_cmd(&pc, 0);
                        (void) idefloppy_queue_pc_tail(drive, &pc);
                }
 
-               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+               drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
        }
 
        floppy->openers--;
@@ -1407,15 +1225,17 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy,
-               struct ide_atapi_pc *pc, unsigned long arg, unsigned int cmd)
+static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
+                              unsigned long arg, unsigned int cmd)
 {
+       idefloppy_floppy_t *floppy = drive->driver_data;
+
        if (floppy->openers > 1)
                return -EBUSY;
 
        /* The IOMEGA Clik! Drive doesn't support this command -
         * no room for an eject mechanism */
-       if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) {
+       if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
                int prevent = arg ? 1 : 0;
 
                if (cmd == CDROMEJECT)
@@ -1436,16 +1256,17 @@ static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy,
 static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
                                  int __user *arg)
 {
-       int blocks, length, flags, err = 0;
        struct ide_atapi_pc pc;
+       ide_drive_t *drive = floppy->drive;
+       int blocks, length, flags, err = 0;
 
        if (floppy->openers > 1) {
                /* Don't format if someone is using the disk */
-               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+               drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
                return -EBUSY;
        }
 
-       floppy->flags |= IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+       drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS;
 
        /*
         * Send ATAPI_FORMAT_UNIT to the drive.
@@ -1469,15 +1290,15 @@ static int ide_floppy_format_unit(idefloppy_floppy_t *floppy,
                goto out;
        }
 
-       (void) idefloppy_get_sfrp_bit(floppy->drive);
+       (void) idefloppy_get_sfrp_bit(drive);
        idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
 
-       if (idefloppy_queue_pc_tail(floppy->drive, &pc))
+       if (idefloppy_queue_pc_tail(drive, &pc))
                err = -EIO;
 
 out:
        if (err)
-               floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS;
+               drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
        return err;
 }
 
@@ -1496,7 +1317,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file,
        case CDROMEJECT:
                /* fall through */
        case CDROM_LOCKDOOR:
-               return ide_floppy_lockdoor(floppy, &pc, arg, cmd);
+               return ide_floppy_lockdoor(drive, &pc, arg, cmd);
        case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
                return 0;
        case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY:
@@ -1537,8 +1358,8 @@ static int idefloppy_media_changed(struct gendisk *disk)
                drive->attach = 0;
                return 0;
        }
-       ret = !!(floppy->flags & IDEFLOPPY_FLAG_MEDIA_CHANGED);
-       floppy->flags &= ~IDEFLOPPY_FLAG_MEDIA_CHANGED;
+       ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
+       drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED;
        return ret;
 }
 
@@ -1575,11 +1396,6 @@ static int ide_floppy_probe(ide_drive_t *drive)
                                " of ide-floppy\n", drive->name);
                goto failed;
        }
-       if (drive->scsi) {
-               printk(KERN_INFO "ide-floppy: passing drive %s to ide-scsi"
-                               " emulation.\n", drive->name);
-               goto failed;
-       }
        floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
        if (!floppy) {
                printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"