]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-floppy.c
ide: add ide_queue_pc_tail() helper
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-floppy.c
index a0a8ad3a3038ca3d1050edc3d86d6ad98f07d8ff..de611c57b2805dc5f91577c5cbf7b058273e9ff0 100644 (file)
  */
 #define IDEFLOPPY_MAX_PC_RETRIES       3
 
-/*
- * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
- * bytes.
- */
-#define IDEFLOPPY_PC_BUFFER_SIZE       256
-
 /* format capacities descriptor codes */
 #define CAPACITY_INVALID       0x00
 #define CAPACITY_UNFORMATTED   0x01
@@ -208,51 +202,6 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
        return 0;
 }
 
-static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
-                                 unsigned int bcount, int direction)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       const struct ide_tp_ops *tp_ops = hwif->tp_ops;
-       xfer_func_t *xf = direction ? tp_ops->output_data : tp_ops->input_data;
-       struct scatterlist *sg = pc->sg;
-       char *buf;
-       int count, done = 0;
-
-       while (bcount) {
-               count = min(sg->length - pc->b_count, bcount);
-               if (PageHighMem(sg_page(sg))) {
-                       unsigned long flags;
-
-                       local_irq_save(flags);
-                       buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset;
-                       xf(drive, NULL, buf + pc->b_count, count);
-                       kunmap_atomic(buf - sg->offset, KM_IRQ0);
-                       local_irq_restore(flags);
-               } else {
-                       buf = sg_virt(sg);
-                       xf(drive, NULL, buf + pc->b_count, count);
-               }
-               bcount -= count;
-               pc->b_count += count;
-               done += count;
-
-               if (pc->b_count == sg->length) {
-                       if (!--pc->sg_cnt)
-                               break;
-                       pc->sg = sg = sg_next(sg);
-                       pc->b_count = 0;
-               }
-       }
-
-       idefloppy_end_request(drive, 1, done >> 9);
-
-       if (bcount) {
-               printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n",
-                               drive->name, __func__, bcount);
-               ide_pad_transfer(drive, direction, bcount);
-       }
-}
-
 static void idefloppy_update_buffers(ide_drive_t *drive,
                                struct ide_atapi_pc *pc)
 {
@@ -263,25 +212,6 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
                idefloppy_end_request(drive, 1, 0);
 }
 
-/*
- * Generate a new packet command request in front of the request queue, before
- * the current request so that it will be processed immediately, on the next
- * pass through the driver.
- */
-static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc,
-               struct request *rq)
-{
-       struct ide_floppy_obj *floppy = drive->driver_data;
-
-       blk_rq_init(NULL, rq);
-       rq->buffer = (char *) 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);
-}
-
 static void ide_floppy_callback(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
@@ -319,16 +249,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
        idefloppy_end_request(drive, uptodate, 0);
 }
 
-static void idefloppy_init_pc(struct ide_atapi_pc *pc)
-{
-       memset(pc, 0, sizeof(*pc));
-       pc->buf = pc->pc_buf;
-       pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
-}
-
 static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
 {
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_REQUEST_SENSE;
        pc->c[4] = 255;
        pc->req_xfer = 18;
@@ -346,7 +269,7 @@ static void idefloppy_retry_pc(ide_drive_t *drive)
 
        (void)ide_read_error(drive);
        idefloppy_create_request_sense_cmd(pc);
-       idefloppy_queue_pc_head(drive, pc, rq);
+       ide_queue_pc_head(drive, floppy->disk, pc, rq);
 }
 
 /* The usual interrupt handler called during a packet command. */
@@ -356,7 +279,7 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
 
        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);
+                          idefloppy_retry_pc, NULL, ide_io_buffers);
 }
 
 /*
@@ -458,14 +381,14 @@ static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
 {
        debug_log("creating prevent removal command, prevent = %d\n", prevent);
 
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
        pc->c[4] = prevent;
 }
 
 static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
 {
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
        pc->c[7] = 255;
        pc->c[8] = 255;
@@ -475,7 +398,7 @@ static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
 static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
                int l, int flags)
 {
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_FORMAT_UNIT;
        pc->c[1] = 0x17;
 
@@ -499,7 +422,7 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
 {
        u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
 
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_MODE_SENSE_10;
        pc->c[1] = 0;
        pc->c[2] = page_code;
@@ -521,7 +444,7 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
 
 static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
 {
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = GPCMD_START_STOP_UNIT;
        pc->c[4] = start;
 }
@@ -537,7 +460,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
        debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
                block, blocks);
 
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
        put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
        put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
@@ -556,7 +479,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
 static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
                struct ide_atapi_pc *pc, struct request *rq)
 {
-       idefloppy_init_pc(pc);
+       ide_init_pc(pc);
        memcpy(pc->c, rq->cmd, sizeof(pc->c));
        pc->rq = rq;
        pc->b_count = 0;
@@ -630,26 +553,6 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
        return idefloppy_issue_pc(drive, pc);
 }
 
-/*
- * Add a special packet command request to the tail of the request queue,
- * and wait for it to be serviced.
- */
-static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
-{
-       struct ide_floppy_obj *floppy = drive->driver_data;
-       struct request *rq;
-       int error;
-
-       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);
-
-       return error;
-}
-
 /*
  * Look at the flexible disk page parameters. We ignore the CHS capacity
  * parameters and use the LBA parameters instead.
@@ -657,6 +560,7 @@ static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
 static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
+       struct gendisk *disk = floppy->disk;
        struct ide_atapi_pc pc;
        u8 *page;
        int capacity, lba_capacity;
@@ -665,13 +569,13 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
 
        idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
 
-       if (idefloppy_queue_pc_tail(drive, &pc)) {
+       if (ide_queue_pc_tail(drive, disk, &pc)) {
                printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
                                " parameters\n");
                return 1;
        }
        floppy->wp = !!(pc.buf[3] & 0x80);
-       set_disk_ro(floppy->disk, floppy->wp);
+       set_disk_ro(disk, floppy->wp);
        page = &pc.buf[8];
 
        transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]);
@@ -715,7 +619,7 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
        idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE);
        pc.flags |= PC_FLAG_SUPPRESS_ERROR;
 
-       if (idefloppy_queue_pc_tail(drive, &pc))
+       if (ide_queue_pc_tail(drive, floppy->disk, &pc))
                return 1;
 
        floppy->srfp = pc.buf[8 + 2] & 0x40;
@@ -729,6 +633,7 @@ static int idefloppy_get_sfrp_bit(ide_drive_t *drive)
 static int ide_floppy_get_capacity(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
+       struct gendisk *disk = floppy->disk;
        struct ide_atapi_pc pc;
        u8 *cap_desc;
        u8 header_len, desc_cnt;
@@ -741,7 +646,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        set_capacity(floppy->disk, 0);
 
        idefloppy_create_read_capacity_cmd(&pc);
-       if (idefloppy_queue_pc_tail(drive, &pc)) {
+       if (ide_queue_pc_tail(drive, disk, &pc)) {
                printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
                return 1;
        }
@@ -816,7 +721,8 @@ static int ide_floppy_get_capacity(ide_drive_t *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);
+       set_capacity(disk, floppy->blocks * floppy->bs_factor);
+
        return rc;
 }
 
@@ -841,6 +747,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
 
 static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
 {
+       struct ide_floppy_obj *floppy = drive->driver_data;
        struct ide_atapi_pc pc;
        u8 header_len, desc_cnt;
        int i, blocks, length, u_array_size, u_index;
@@ -853,7 +760,7 @@ static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg)
                return -EINVAL;
 
        idefloppy_create_read_capacity_cmd(&pc);
-       if (idefloppy_queue_pc_tail(drive, &pc)) {
+       if (ide_queue_pc_tail(drive, floppy->disk, &pc)) {
                printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
                return -EIO;
        }
@@ -915,7 +822,7 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
 
        if (floppy->srfp) {
                idefloppy_create_request_sense_cmd(&pc);
-               if (idefloppy_queue_pc_tail(drive, &pc))
+               if (ide_queue_pc_tail(drive, floppy->disk, &pc))
                        return -EIO;
 
                if (floppy->sense_key == 2 &&
@@ -1083,6 +990,18 @@ static ide_driver_t idefloppy_driver = {
 #endif
 };
 
+static void ide_floppy_set_media_lock(ide_drive_t *drive, int on)
+{
+       struct ide_floppy_obj *floppy = drive->driver_data;
+       struct ide_atapi_pc pc;
+
+       /* IOMEGA Clik! drives do not support lock/unlock commands */
+       if ((drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE) == 0) {
+               idefloppy_create_prevent_cmd(&pc, on);
+               (void)ide_queue_pc_tail(drive, floppy->disk, &pc);
+       }
+}
+
 static int idefloppy_open(struct inode *inode, struct file *filp)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
@@ -1105,12 +1024,12 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
                drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
                /* Just in case */
 
-               idefloppy_init_pc(&pc);
+               ide_init_pc(&pc);
                pc.c[0] = GPCMD_TEST_UNIT_READY;
 
-               if (idefloppy_queue_pc_tail(drive, &pc)) {
+               if (ide_queue_pc_tail(drive, disk, &pc)) {
                        idefloppy_create_start_stop_cmd(&pc, 1);
-                       (void) idefloppy_queue_pc_tail(drive, &pc);
+                       (void)ide_queue_pc_tail(drive, disk, &pc);
                }
 
                if (ide_floppy_get_capacity(drive)
@@ -1129,12 +1048,9 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
                        ret = -EROFS;
                        goto out_put_floppy;
                }
+
                drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED;
-               /* IOMEGA Clik! drives do not support lock/unlock commands */
-               if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-                       idefloppy_create_prevent_cmd(&pc, 1);
-                       (void) idefloppy_queue_pc_tail(drive, &pc);
-               }
+               ide_floppy_set_media_lock(drive, 1);
                check_disk_change(inode->i_bdev);
        } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) {
                ret = -EBUSY;
@@ -1153,17 +1069,11 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
        struct gendisk *disk = inode->i_bdev->bd_disk;
        struct ide_floppy_obj *floppy = ide_floppy_g(disk);
        ide_drive_t *drive = floppy->drive;
-       struct ide_atapi_pc pc;
 
        debug_log("Reached %s\n", __func__);
 
        if (floppy->openers == 1) {
-               /* IOMEGA Clik! drives do not support lock/unlock commands */
-               if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-                       idefloppy_create_prevent_cmd(&pc, 0);
-                       (void) idefloppy_queue_pc_tail(drive, &pc);
-               }
-
+               ide_floppy_set_media_lock(drive, 0);
                drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
        }
 
@@ -1189,25 +1099,16 @@ 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;
+       int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
 
        if (floppy->openers > 1)
                return -EBUSY;
 
-       /* The IOMEGA Clik! Drive doesn't support this command -
-        * no room for an eject mechanism */
-       if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) {
-               int prevent = arg ? 1 : 0;
-
-               if (cmd == CDROMEJECT)
-                       prevent = 0;
-
-               idefloppy_create_prevent_cmd(pc, prevent);
-               (void) idefloppy_queue_pc_tail(floppy->drive, pc);
-       }
+       ide_floppy_set_media_lock(drive, prevent);
 
        if (cmd == CDROMEJECT) {
                idefloppy_create_start_stop_cmd(pc, 2);
-               (void) idefloppy_queue_pc_tail(floppy->drive, pc);
+               (void)ide_queue_pc_tail(drive, floppy->disk, pc);
        }
 
        return 0;
@@ -1252,7 +1153,7 @@ static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg)
        (void) idefloppy_get_sfrp_bit(drive);
        idefloppy_create_format_unit_cmd(&pc, blocks, length, flags);
 
-       if (idefloppy_queue_pc_tail(drive, &pc))
+       if (ide_queue_pc_tail(drive, floppy->disk, &pc))
                err = -EIO;
 
 out: