ALSA: usb-audio: add support for Akai MPD16
[safe/jmp/linux-2.6] / drivers / ide / ide-tape.c
index d5e9bb2..b072328 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/major.h>
 #include <linux/errno.h>
 #include <linux/genhd.h>
+#include <linux/seq_file.h>
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/ide.h>
 #include <asm/unaligned.h>
 #include <linux/mtio.h>
 
-enum {
-       /* output errors only */
-       DBG_ERR =               (1 << 0),
-       /* output all sense key/asc */
-       DBG_SENSE =             (1 << 1),
-       /* info regarding all chrdev-related procedures */
-       DBG_CHRDEV =            (1 << 2),
-       /* all remaining procedures */
-       DBG_PROCS =             (1 << 3),
-};
-
 /* define to see debug info */
-#define IDETAPE_DEBUG_LOG              0
+#undef IDETAPE_DEBUG_LOG
 
-#if IDETAPE_DEBUG_LOG
-#define debug_log(lvl, fmt, args...)                   \
-{                                                      \
-       if (tape->debug_mask & lvl)                     \
-       printk(KERN_INFO "ide-tape: " fmt, ## args);    \
-}
+#ifdef IDETAPE_DEBUG_LOG
+#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, ## args)
 #else
-#define debug_log(lvl, fmt, args...) do {} while (0)
+#define ide_debug_log(lvl, fmt, args...) do {} while (0)
 #endif
 
 /**************************** Tunable parameters *****************************/
@@ -170,7 +156,8 @@ typedef struct ide_tape_obj {
         * other device. Note that at most we will have only one DSC (usually
         * data transfer) request in the device request queue.
         */
-       struct request *postponed_rq;
+       bool postponed_rq;
+
        /* The time in which we started polling for DSC */
        unsigned long dsc_polling_start;
        /* Timer used to poll for dsc */
@@ -230,28 +217,37 @@ typedef struct ide_tape_obj {
        char drv_write_prot;
        /* the tape is write protected (hardware or opened as read-only) */
        char write_prot;
-
-       u32 debug_mask;
 } idetape_tape_t;
 
 static DEFINE_MUTEX(idetape_ref_mutex);
 
+static DEFINE_MUTEX(idetape_chrdev_mutex);
+
 static struct class *idetape_sysfs_class;
 
 static void ide_tape_release(struct device *);
 
-static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
+static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
+
+static struct ide_tape_obj *ide_tape_get(struct gendisk *disk, bool cdev,
+                                        unsigned int i)
 {
        struct ide_tape_obj *tape = NULL;
 
        mutex_lock(&idetape_ref_mutex);
-       tape = ide_drv_g(disk, ide_tape_obj);
+
+       if (cdev)
+               tape = idetape_devs[i];
+       else
+               tape = ide_drv_g(disk, ide_tape_obj);
+
        if (tape) {
                if (ide_device_get(tape->drive))
                        tape = NULL;
                else
                        get_device(&tape->dev);
        }
+
        mutex_unlock(&idetape_ref_mutex);
        return tape;
 }
@@ -267,44 +263,27 @@ static void ide_tape_put(struct ide_tape_obj *tape)
 }
 
 /*
- * The variables below are used for the character device interface. Additional
- * state variables are defined in our ide_drive_t structure.
- */
-static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
-
-static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
-{
-       struct ide_tape_obj *tape = NULL;
-
-       mutex_lock(&idetape_ref_mutex);
-       tape = idetape_devs[i];
-       if (tape)
-               get_device(&tape->dev);
-       mutex_unlock(&idetape_ref_mutex);
-       return tape;
-}
-
-/*
  * called on each failed packet command retry to analyze the request sense. We
  * currently do not utilize this information.
  */
-static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
+static void idetape_analyze_error(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc *pc = drive->failed_pc;
+       struct request *rq = drive->hwif->rq;
+       u8 *sense = bio_data(rq->bio);
 
        tape->sense_key = sense[2] & 0xF;
        tape->asc       = sense[12];
        tape->ascq      = sense[13];
 
-       debug_log(DBG_ERR, "pc = %x, sense key = %x, asc = %x, ascq = %x\n",
-                pc->c[0], tape->sense_key, tape->asc, tape->ascq);
+       ide_debug_log(IDE_DBG_FUNC,
+                     "cmd: 0x%x, sense key = %x, asc = %x, ascq = %x",
+                     rq->cmd[0], tape->sense_key, tape->asc, tape->ascq);
 
-       /* Correct pc->xferred by asking the tape.       */
+       /* correct remaining bytes to transfer */
        if (pc->flags & PC_FLAG_DMA_ERROR)
-               pc->xferred = pc->req_xfer -
-                       tape->blk_size *
-                       get_unaligned_be32(&sense[3]);
+               rq->resid_len = tape->blk_size * get_unaligned_be32(&sense[3]);
 
        /*
         * If error was the result of a zero-length read or write command,
@@ -338,7 +317,7 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
                        pc->flags |= PC_FLAG_ABORT;
                }
                if (!(pc->flags & PC_FLAG_ABORT) &&
-                   pc->xferred)
+                   (blk_rq_bytes(rq) - rq->resid_len))
                        pc->retries = IDETAPE_MAX_PC_RETRIES + 1;
        }
 }
@@ -353,7 +332,8 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
        int uptodate = pc->error ? 0 : 1;
        int err = uptodate ? 0 : IDE_DRV_ERROR_GENERAL;
 
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc: %d, err: %d", rq->cmd[0],
+                     dsc, err);
 
        if (dsc)
                ide_tape_handle_dsc(drive);
@@ -363,12 +343,13 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
 
        if (pc->c[0] == REQUEST_SENSE) {
                if (uptodate)
-                       idetape_analyze_error(drive, pc->buf);
+                       idetape_analyze_error(drive);
                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) {
-               int blocks = pc->xferred / tape->blk_size;
+               unsigned int blocks =
+                       (blk_rq_bytes(rq) - rq->resid_len) / tape->blk_size;
 
                tape->avg_size += blocks * tape->blk_size;
 
@@ -380,36 +361,12 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
                }
 
                tape->first_frame += blocks;
-               rq->data_len -= blocks * tape->blk_size;
 
                if (pc->error) {
                        uptodate = 0;
                        err = pc->error;
                }
-       } else if (pc->c[0] == READ_POSITION && uptodate) {
-               u8 *readpos = 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(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
-                       uptodate = 0;
-                       err = IDE_DRV_ERROR_GENERAL;
-               } else {
-                       debug_log(DBG_SENSE, "Block Location - %u\n",
-                                       be32_to_cpup((__be32 *)&readpos[4]));
-
-                       tape->partition = readpos[1];
-                       tape->first_frame = be32_to_cpup((__be32 *)&readpos[4]);
-                       set_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags);
-               }
        }
-
        rq->errors = err;
 
        return uptodate;
@@ -419,13 +376,14 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
  * Postpone the current request so that ide.c will be able to service requests
  * from another device on the same port while we are polling for DSC.
  */
-static void idetape_postpone_request(ide_drive_t *drive)
+static void ide_tape_stall_queue(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, dsc_poll_freq: %lu",
+                     drive->hwif->rq->cmd[0], tape->dsc_poll_freq);
 
-       tape->postponed_rq = drive->hwif->rq;
+       tape->postponed_rq = true;
 
        ide_stall_queue(drive, tape->dsc_poll_freq);
 }
@@ -439,7 +397,7 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
        tape->dsc_poll_freq = IDETAPE_DSC_MA_FAST;
        tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
        /* Allow ide.c to handle other requests */
-       idetape_postpone_request(drive);
+       ide_tape_stall_queue(drive);
 }
 
 /*
@@ -484,6 +442,7 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
                                         struct ide_atapi_pc *pc)
 {
        idetape_tape_t *tape = drive->driver_data;
+       struct request *rq = drive->hwif->rq;
 
        if (drive->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
                drive->failed_pc = pc;
@@ -493,7 +452,6 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
 
        if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
                (pc->flags & PC_FLAG_ABORT)) {
-               unsigned int done = blk_rq_bytes(drive->hwif->rq);
 
                /*
                 * We will "abort" retrying a packet command in case legitimate
@@ -517,10 +475,11 @@ static ide_startstop_t ide_tape_issue_pc(ide_drive_t *drive,
 
                drive->failed_pc = NULL;
                drive->pc_callback(drive, 0);
-               ide_complete_rq(drive, -EIO, done);
+               ide_complete_rq(drive, -EIO, blk_rq_bytes(rq));
                return ide_stopped;
        }
-       debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
+       ide_debug_log(IDE_DBG_SENSE, "retry #%d, cmd: 0x%02x", pc->retries,
+                     pc->c[0]);
 
        pc->retries++;
 
@@ -586,16 +545,13 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
                                   struct ide_atapi_pc *pc, struct request *rq,
                                   u8 opcode)
 {
-       unsigned int length = rq->nr_sectors;
+       unsigned int length = blk_rq_sectors(rq) / (tape->blk_size >> 9);
 
        ide_init_pc(pc);
        put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
-       pc->bh = NULL;
-       pc->buf = NULL;
-       pc->buf_size = length * tape->blk_size;
-       pc->req_xfer = pc->buf_size;
-       if (pc->req_xfer == tape->buffer_size)
+
+       if (blk_rq_bytes(rq) == tape->buffer_size)
                pc->flags |= PC_FLAG_DMA_OK;
 
        if (opcode == READ_6)
@@ -614,22 +570,14 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
        ide_hwif_t *hwif = drive->hwif;
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc *pc = NULL;
-       struct request *postponed_rq = tape->postponed_rq;
        struct ide_cmd cmd;
        u8 stat;
 
-       debug_log(DBG_SENSE, "sector: %llu, nr_sectors: %lu\n"
-                 (unsigned long long)rq->sector, rq->nr_sectors);
+       ide_debug_log(IDE_DBG_RQ, "cmd: 0x%x, sector: %llu, nr_sectors: %u",
+                     rq->cmd[0], (unsigned long long)blk_rq_pos(rq),
+                     blk_rq_sectors(rq));
 
-       if (!(blk_special_request(rq) || blk_sense_request(rq))) {
-               /* We do not support buffer cache originated requests. */
-               printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
-                       "request queue (%d)\n", drive->name, rq->cmd_type);
-               if (blk_fs_request(rq) == 0 && rq->errors == 0)
-                       rq->errors = -EIO;
-               ide_complete_rq(drive, -EIO, ide_rq_bytes(rq));
-               return ide_stopped;
-       }
+       BUG_ON(!(blk_special_request(rq) || blk_sense_request(rq)));
 
        /* Retry a failed packet command */
        if (drive->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
@@ -637,18 +585,6 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                goto out;
        }
 
-       if (postponed_rq != NULL)
-               if (rq != postponed_rq) {
-                       printk(KERN_ERR "ide-tape: ide-tape.c bug - "
-                                       "Two DSC requests were queued\n");
-                       drive->failed_pc = NULL;
-                       rq->errors = 0;
-                       ide_complete_rq(drive, 0, blk_rq_bytes(rq));
-                       return ide_stopped;
-               }
-
-       tape->postponed_rq = NULL;
-
        /*
         * If the tape is still busy, postpone our request and service
         * the other device meanwhile.
@@ -657,16 +593,16 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
 
        if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
            (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
-               set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
+               drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
 
        if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
-               set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
+               drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
                drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
        }
 
-       if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
-           (stat & ATA_DSC) == 0) {
-               if (postponed_rq == NULL) {
+       if (!(drive->atapi_flags & IDE_AFLAG_IGNORE_DSC) &&
+           !(stat & ATA_DSC)) {
+               if (!tape->postponed_rq) {
                        tape->dsc_polling_start = jiffies;
                        tape->dsc_poll_freq = tape->best_dsc_rw_freq;
                        tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
@@ -683,9 +619,13 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                                        tape->dsc_polling_start +
                                        IDETAPE_DSC_MA_THRESHOLD))
                        tape->dsc_poll_freq = IDETAPE_DSC_MA_SLOW;
-               idetape_postpone_request(drive);
+               ide_tape_stall_queue(drive);
                return ide_stopped;
+       } else {
+               drive->atapi_flags &= ~IDE_AFLAG_IGNORE_DSC;
+               tape->postponed_rq = false;
        }
+
        if (rq->cmd[13] & REQ_IDETAPE_READ) {
                pc = &tape->queued_pc;
                ide_tape_create_rw_cmd(tape, pc, rq, READ_6);
@@ -719,7 +659,7 @@ out:
 
        cmd.rq = rq;
 
-       ide_init_sg_cmd(&cmd, pc->req_xfer);
+       ide_init_sg_cmd(&cmd, blk_rq_bytes(rq));
        ide_map_sg(drive, &cmd);
 
        return ide_tape_issue_pc(drive, &cmd, pc);
@@ -745,7 +685,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
        int load_attempted = 0;
 
        /* Wait for the tape to become ready */
-       set_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
+       set_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT), &drive->atapi_flags);
        timeout += jiffies;
        while (time_before(jiffies, timeout)) {
                if (ide_do_test_unit_ready(drive, disk) == 0)
@@ -773,33 +713,53 @@ static int idetape_flush_tape_buffers(ide_drive_t *drive)
        int rc;
 
        idetape_create_write_filemark_cmd(drive, &pc, 0);
-       rc = ide_queue_pc_tail(drive, tape->disk, &pc);
+       rc = ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0);
        if (rc)
                return rc;
        idetape_wait_ready(drive, 60 * 5 * HZ);
        return 0;
 }
 
-static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
-{
-       ide_init_pc(pc);
-       pc->c[0] = READ_POSITION;
-       pc->req_xfer = 20;
-}
-
-static int idetape_read_position(ide_drive_t *drive)
+static int ide_tape_read_position(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc pc;
-       int position;
+       u8 buf[20];
+
+       ide_debug_log(IDE_DBG_FUNC, "enter");
 
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+       /* prep cmd */
+       ide_init_pc(&pc);
+       pc.c[0] = READ_POSITION;
+       pc.req_xfer = 20;
 
-       idetape_create_read_position_cmd(&pc);
-       if (ide_queue_pc_tail(drive, tape->disk, &pc))
+       if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer))
                return -1;
-       position = tape->first_frame;
-       return position;
+
+       if (!pc.error) {
+               ide_debug_log(IDE_DBG_FUNC, "BOP - %s",
+                               (buf[0] & 0x80) ? "Yes" : "No");
+               ide_debug_log(IDE_DBG_FUNC, "EOP - %s",
+                               (buf[0] & 0x40) ? "Yes" : "No");
+
+               if (buf[0] & 0x4) {
+                       printk(KERN_INFO "ide-tape: Block location is unknown"
+                                        "to the tape\n");
+                       clear_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
+                                 &drive->atapi_flags);
+                       return -1;
+               } else {
+                       ide_debug_log(IDE_DBG_FUNC, "Block Location: %u",
+                                     be32_to_cpup((__be32 *)&buf[4]));
+
+                       tape->partition = buf[1];
+                       tape->first_frame = be32_to_cpup((__be32 *)&buf[4]);
+                       set_bit(ilog2(IDE_AFLAG_ADDRESS_VALID),
+                               &drive->atapi_flags);
+               }
+       }
+
+       return tape->first_frame;
 }
 
 static void idetape_create_locate_cmd(ide_drive_t *drive,
@@ -821,7 +781,7 @@ static void __ide_tape_discard_merge_buffer(ide_drive_t *drive)
        if (tape->chrdev_dir != IDETAPE_DIR_READ)
                return;
 
-       clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags);
+       clear_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags);
        tape->valid = 0;
        if (tape->buf != NULL) {
                kfree(tape->buf);
@@ -842,19 +802,21 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block,
 {
        idetape_tape_t *tape = drive->driver_data;
        struct gendisk *disk = tape->disk;
-       int retval;
+       int ret;
        struct ide_atapi_pc pc;
 
        if (tape->chrdev_dir == IDETAPE_DIR_READ)
                __ide_tape_discard_merge_buffer(drive);
        idetape_wait_ready(drive, 60 * 5 * HZ);
        idetape_create_locate_cmd(drive, &pc, block, partition, skip);
-       retval = ide_queue_pc_tail(drive, disk, &pc);
-       if (retval)
-               return (retval);
+       ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
+       if (ret)
+               return ret;
 
-       idetape_create_read_position_cmd(&pc);
-       return ide_queue_pc_tail(drive, disk, &pc);
+       ret = ide_tape_read_position(drive);
+       if (ret < 0)
+               return ret;
+       return 0;
 }
 
 static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
@@ -865,7 +827,7 @@ static void ide_tape_discard_merge_buffer(ide_drive_t *drive,
 
        __ide_tape_discard_merge_buffer(drive);
        if (restore_position) {
-               position = idetape_read_position(drive);
+               position = ide_tape_read_position(drive);
                seek = position > 0 ? position : 0;
                if (idetape_position_tape(drive, seek, 0, 0)) {
                        printk(KERN_INFO "ide-tape: %s: position_tape failed in"
@@ -885,7 +847,8 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
        struct request *rq;
        int ret;
 
-       debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
+       ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x, size: %d", cmd, size);
+
        BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
        BUG_ON(size < 0 || size % tape->blk_size);
 
@@ -893,7 +856,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
        rq->cmd_type = REQ_TYPE_SPECIAL;
        rq->cmd[13] = cmd;
        rq->rq_disk = tape->disk;
-       rq->sector = tape->first_frame;
+       rq->__sector = tape->first_frame;
 
        if (size) {
                ret = blk_rq_map_kern(drive->queue, rq, tape->buf, size,
@@ -905,7 +868,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int size)
        blk_execute_rq(drive->queue, tape->disk, rq, 0);
 
        /* calculate the number of transferred bytes and update buffer state */
-       size -= rq->data_len;
+       size -= rq->resid_len;
        tape->cur = tape->buf;
        if (cmd == REQ_IDETAPE_READ)
                tape->valid = size;
@@ -953,14 +916,6 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
        pc->flags |= PC_FLAG_WAIT_FOR_DSC;
 }
 
-/* Queue up a character device originated write request. */
-static int idetape_add_chrdev_write_request(ide_drive_t *drive, int size)
-{
-       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
-
-       return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, size);
-}
-
 static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
@@ -974,7 +929,7 @@ static void ide_tape_flush_merge_buffer(ide_drive_t *drive)
                size_t aligned = roundup(tape->valid, tape->blk_size);
 
                memset(tape->cur, 0, aligned - tape->valid);
-               idetape_add_chrdev_write_request(drive, aligned);
+               idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, aligned);
                kfree(tape->buf);
                tape->buf = NULL;
        }
@@ -1031,20 +986,6 @@ static int idetape_init_rw(ide_drive_t *drive, int dir)
        return 0;
 }
 
-/* called from idetape_chrdev_read() to service a chrdev read request. */
-static int idetape_add_chrdev_read_request(ide_drive_t *drive, int size)
-{
-       debug_log(DBG_PROCS, "Enter %s, %d bytes\n", __func__, size);
-
-       /* If we are at a filemark, return a read length of 0 */
-       if (test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
-               return 0;
-
-       idetape_init_rw(drive, IDETAPE_DIR_READ);
-
-       return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, size);
-}
-
 static void idetape_pad_zeros(ide_drive_t *drive, int bcount)
 {
        idetape_tape_t *tape = drive->driver_data;
@@ -1067,20 +1008,19 @@ static int idetape_rewind_tape(ide_drive_t *drive)
 {
        struct ide_tape_obj *tape = drive->driver_data;
        struct gendisk *disk = tape->disk;
-       int retval;
        struct ide_atapi_pc pc;
+       int ret;
 
-       debug_log(DBG_SENSE, "Enter %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "enter");
 
        idetape_create_rewind_cmd(drive, &pc);
-       retval = ide_queue_pc_tail(drive, disk, &pc);
-       if (retval)
-               return retval;
+       ret = ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
+       if (ret)
+               return ret;
 
-       idetape_create_read_position_cmd(&pc);
-       retval = ide_queue_pc_tail(drive, disk, &pc);
-       if (retval)
-               return retval;
+       ret = ide_tape_read_position(drive);
+       if (ret < 0)
+               return ret;
        return 0;
 }
 
@@ -1097,7 +1037,7 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
                int nr_stages;
        } config;
 
-       debug_log(DBG_PROCS, "Enter %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%04x", cmd);
 
        switch (cmd) {
        case 0x0340:
@@ -1106,6 +1046,7 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
                tape->best_dsc_rw_freq = config.dsc_rw_frequency;
                break;
        case 0x0350:
+               memset(&config, 0, sizeof(config));
                config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
                config.nr_stages = 1;
                if (copy_to_user(argp, &config, sizeof(config)))
@@ -1126,6 +1067,9 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
        int retval, count = 0;
        int sprev = !!(tape->caps[4] & 0x20);
 
+
+       ide_debug_log(IDE_DBG_FUNC, "mt_op: %d, mt_count: %d", mt_op, mt_count);
+
        if (mt_count == 0)
                return 0;
        if (MTBSF == mt_op || MTBSFM == mt_op) {
@@ -1136,7 +1080,8 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
 
        if (tape->chrdev_dir == IDETAPE_DIR_READ) {
                tape->valid = 0;
-               if (test_and_clear_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags))
+               if (test_and_clear_bit(ilog2(IDE_AFLAG_FILEMARK),
+                                      &drive->atapi_flags))
                        ++count;
                ide_tape_discard_merge_buffer(drive, 0);
        }
@@ -1146,7 +1091,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
        case MTBSF:
                idetape_create_space_cmd(&pc, mt_count - count,
                                         IDETAPE_SPACE_OVER_FILEMARK);
-               return ide_queue_pc_tail(drive, disk, &pc);
+               return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
        case MTFSFM:
        case MTBSFM:
                if (!sprev)
@@ -1184,63 +1129,54 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
 {
        struct ide_tape_obj *tape = file->private_data;
        ide_drive_t *drive = tape->drive;
-       ssize_t bytes_read, temp, actually_read = 0, rc;
+       size_t done = 0;
        ssize_t ret = 0;
+       int rc;
 
-       debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
+       ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
 
        if (tape->chrdev_dir != IDETAPE_DIR_READ) {
-               if (test_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags))
+               if (test_bit(ilog2(IDE_AFLAG_DETECT_BS), &drive->atapi_flags))
                        if (count > tape->blk_size &&
                            (count % tape->blk_size) == 0)
                                tape->user_bs_factor = count / tape->blk_size;
        }
+
        rc = idetape_init_rw(drive, IDETAPE_DIR_READ);
        if (rc < 0)
                return rc;
-       if (count == 0)
-               return (0);
-       if (tape->valid) {
-               actually_read = min_t(unsigned int, tape->valid, count);
-               if (copy_to_user(buf, tape->cur, actually_read))
-                       ret = -EFAULT;
-               buf += actually_read;
-               count -= actually_read;
-               tape->cur += actually_read;
-               tape->valid -= actually_read;
-       }
-       while (count >= tape->buffer_size) {
-               bytes_read = idetape_add_chrdev_read_request(drive,
-                                                            tape->buffer_size);
-               if (bytes_read <= 0)
-                       goto finish;
-               if (copy_to_user(buf, tape->cur, bytes_read))
-                       ret = -EFAULT;
-               buf += bytes_read;
-               count -= bytes_read;
-               actually_read += bytes_read;
-       }
-       if (count) {
-               bytes_read = idetape_add_chrdev_read_request(drive,
-                                                            tape->buffer_size);
-               if (bytes_read <= 0)
-                       goto finish;
-               temp = min((unsigned long)count, (unsigned long)bytes_read);
-               if (copy_to_user(buf, tape->cur, temp))
+
+       while (done < count) {
+               size_t todo;
+
+               /* refill if staging buffer is empty */
+               if (!tape->valid) {
+                       /* If we are at a filemark, nothing more to read */
+                       if (test_bit(ilog2(IDE_AFLAG_FILEMARK),
+                                    &drive->atapi_flags))
+                               break;
+                       /* read */
+                       if (idetape_queue_rw_tail(drive, REQ_IDETAPE_READ,
+                                                 tape->buffer_size) <= 0)
+                               break;
+               }
+
+               /* copy out */
+               todo = min_t(size_t, count - done, tape->valid);
+               if (copy_to_user(buf + done, tape->cur, todo))
                        ret = -EFAULT;
-               actually_read += temp;
-               tape->cur += temp;
-               tape->valid -= temp;
+
+               tape->cur += todo;
+               tape->valid -= todo;
+               done += todo;
        }
-finish:
-       if (!actually_read && test_bit(IDE_AFLAG_FILEMARK, &drive->atapi_flags)) {
-               debug_log(DBG_SENSE, "%s: spacing over filemark\n", tape->name);
 
+       if (!done && test_bit(ilog2(IDE_AFLAG_FILEMARK), &drive->atapi_flags)) {
                idetape_space_over_filemarks(drive, MTFSF, 1);
                return 0;
        }
 
-       return ret ? ret : actually_read;
+       return ret ? ret : done;
 }
 
 static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
@@ -1248,7 +1184,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
 {
        struct ide_tape_obj *tape = file->private_data;
        ide_drive_t *drive = tape->drive;
-       ssize_t actually_written = 0;
+       size_t done = 0;
        ssize_t ret = 0;
        int rc;
 
@@ -1256,53 +1192,34 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
        if (tape->write_prot)
                return -EACCES;
 
-       debug_log(DBG_CHRDEV, "Enter %s, count %Zd\n", __func__, count);
+       ide_debug_log(IDE_DBG_FUNC, "count %Zd", count);
 
        /* Initialize write operation */
        rc = idetape_init_rw(drive, IDETAPE_DIR_WRITE);
        if (rc < 0)
                return rc;
-       if (count == 0)
-               return (0);
-       if (tape->valid < tape->buffer_size) {
-               actually_written = min_t(unsigned int,
-                                        tape->buffer_size - tape->valid,
-                                        count);
-               if (copy_from_user(tape->cur, buf, actually_written))
-                       ret = -EFAULT;
-               buf += actually_written;
-               count -= actually_written;
-               tape->cur += actually_written;
-               tape->valid += actually_written;
-
-               if (tape->valid == tape->buffer_size) {
-                       ssize_t retval;
-                       retval = idetape_add_chrdev_write_request(drive,
-                                                       tape->buffer_size);
-                       if (retval <= 0)
-                               return (retval);
-               }
-       }
-       while (count >= tape->buffer_size) {
-               ssize_t retval;
-               if (copy_from_user(tape->cur, buf, tape->buffer_size))
-                       ret = -EFAULT;
-               buf += tape->buffer_size;
-               count -= tape->buffer_size;
-               retval = idetape_add_chrdev_write_request(drive,
-                                                         tape->buffer_size);
-               actually_written += tape->buffer_size;
-               if (retval <= 0)
-                       return (retval);
-       }
-       if (count) {
-               actually_written += count;
-               if (copy_from_user(tape->cur, buf, count))
+
+       while (done < count) {
+               size_t todo;
+
+               /* flush if staging buffer is full */
+               if (tape->valid == tape->buffer_size &&
+                   idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE,
+                                         tape->buffer_size) <= 0)
+                       return rc;
+
+               /* copy in */
+               todo = min_t(size_t, count - done,
+                            tape->buffer_size - tape->valid);
+               if (copy_from_user(tape->cur, buf + done, todo))
                        ret = -EFAULT;
-               tape->cur += count;
-               tape->valid += count;
+
+               tape->cur += todo;
+               tape->valid += todo;
+               done += todo;
        }
-       return ret ? ret : actually_written;
+
+       return ret ? ret : done;
 }
 
 static int idetape_write_filemark(ide_drive_t *drive)
@@ -1312,7 +1229,7 @@ static int idetape_write_filemark(ide_drive_t *drive)
 
        /* Write a filemark */
        idetape_create_write_filemark_cmd(drive, &pc, 1);
-       if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
+       if (ide_queue_pc_tail(drive, tape->disk, &pc, NULL, 0)) {
                printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
                return -EIO;
        }
@@ -1339,8 +1256,8 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
        struct ide_atapi_pc pc;
        int i, retval;
 
-       debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n",
-                       mt_op, mt_count);
+       ide_debug_log(IDE_DBG_FUNC, "MTIOCTOP ioctl: mt_op: %d, mt_count: %d",
+                     mt_op, mt_count);
 
        switch (mt_op) {
        case MTFSF:
@@ -1386,7 +1303,8 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
                ide_tape_discard_merge_buffer(drive, 0);
                retval = ide_do_start_stop(drive, disk, !IDETAPE_LU_LOAD_MASK);
                if (!retval)
-                       clear_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags);
+                       clear_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT),
+                                 &drive->atapi_flags);
                return retval;
        case MTNOP:
                ide_tape_discard_merge_buffer(drive, 0);
@@ -1397,20 +1315,22 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
                        IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK);
        case MTEOM:
                idetape_create_space_cmd(&pc, 0, IDETAPE_SPACE_TO_EOD);
-               return ide_queue_pc_tail(drive, disk, &pc);
+               return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
        case MTERASE:
                (void)idetape_rewind_tape(drive);
                idetape_create_erase_cmd(&pc);
-               return ide_queue_pc_tail(drive, disk, &pc);
+               return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
        case MTSETBLK:
                if (mt_count) {
                        if (mt_count < tape->blk_size ||
                            mt_count % tape->blk_size)
                                return -EIO;
                        tape->user_bs_factor = mt_count / tape->blk_size;
-                       clear_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
+                       clear_bit(ilog2(IDE_AFLAG_DETECT_BS),
+                                 &drive->atapi_flags);
                } else
-                       set_bit(IDE_AFLAG_DETECT_BS, &drive->atapi_flags);
+                       set_bit(ilog2(IDE_AFLAG_DETECT_BS),
+                               &drive->atapi_flags);
                return 0;
        case MTSEEK:
                ide_tape_discard_merge_buffer(drive, 0);
@@ -1445,7 +1365,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
  * supported here, and not in the corresponding block interface. Our own
  * ide-tape ioctls are supported on both interfaces.
  */
-static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
+static long do_idetape_chrdev_ioctl(struct file *file,
                                unsigned int cmd, unsigned long arg)
 {
        struct ide_tape_obj *tape = file->private_data;
@@ -1456,7 +1376,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
        int block_offset = 0, position = tape->first_frame;
        void __user *argp = (void __user *)arg;
 
-       debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd);
+       ide_debug_log(IDE_DBG_FUNC, "cmd: 0x%x", cmd);
 
        if (tape->chrdev_dir == IDETAPE_DIR_WRITE) {
                ide_tape_flush_merge_buffer(drive);
@@ -1465,7 +1385,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
        if (cmd == MTIOCGET || cmd == MTIOCPOS) {
                block_offset = tape->valid /
                        (tape->blk_size * tape->user_bs_factor);
-               position = idetape_read_position(drive);
+               position = ide_tape_read_position(drive);
                if (position < 0)
                        return -EIO;
        }
@@ -1500,6 +1420,16 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
        }
 }
 
+static long idetape_chrdev_ioctl(struct file *file,
+                               unsigned int cmd, unsigned long arg)
+{
+       long ret;
+       lock_kernel();
+       ret = do_idetape_chrdev_ioctl(file, cmd, arg);
+       unlock_kernel();
+       return ret;
+}
+
 /*
  * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
  * block size with the reported value.
@@ -1508,9 +1438,10 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc pc;
+       u8 buf[12];
 
        idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
-       if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
+       if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
                printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
                if (tape->blk_size == 0) {
                        printk(KERN_WARNING "ide-tape: Cannot deal with zero "
@@ -1519,10 +1450,13 @@ static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
                }
                return;
        }
-       tape->blk_size = (pc.buf[4 + 5] << 16) +
-                               (pc.buf[4 + 6] << 8)  +
-                                pc.buf[4 + 7];
-       tape->drv_write_prot = (pc.buf[2] & 0x80) >> 7;
+       tape->blk_size = (buf[4 + 5] << 16) +
+                               (buf[4 + 6] << 8)  +
+                                buf[4 + 7];
+       tape->drv_write_prot = (buf[2] & 0x80) >> 7;
+
+       ide_debug_log(IDE_DBG_FUNC, "blk_size: %d, write_prot: %d",
+                     tape->blk_size, tape->drv_write_prot);
 }
 
 static int idetape_chrdev_open(struct inode *inode, struct file *filp)
@@ -1535,14 +1469,18 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
        if (i >= MAX_HWIFS * MAX_DRIVES)
                return -ENXIO;
 
-       lock_kernel();
-       tape = ide_tape_chrdev_get(i);
+       mutex_lock(&idetape_chrdev_mutex);
+
+       tape = ide_tape_get(NULL, true, i);
        if (!tape) {
-               unlock_kernel();
+               mutex_unlock(&idetape_chrdev_mutex);
                return -ENXIO;
        }
 
-       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
+       drive = tape->drive;
+       filp->private_data = tape;
+
+       ide_debug_log(IDE_DBG_FUNC, "enter");
 
        /*
         * We really want to do nonseekable_open(inode, filp); here, but some
@@ -1551,24 +1489,21 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
         */
        filp->f_mode &= ~(FMODE_PREAD | FMODE_PWRITE);
 
-       drive = tape->drive;
-
-       filp->private_data = tape;
 
-       if (test_and_set_bit(IDE_AFLAG_BUSY, &drive->atapi_flags)) {
+       if (test_and_set_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags)) {
                retval = -EBUSY;
                goto out_put_tape;
        }
 
        retval = idetape_wait_ready(drive, 60 * HZ);
        if (retval) {
-               clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
+               clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
                printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
                goto out_put_tape;
        }
 
-       idetape_read_position(drive);
-       if (!test_bit(IDE_AFLAG_ADDRESS_VALID, &drive->atapi_flags))
+       ide_tape_read_position(drive);
+       if (!test_bit(ilog2(IDE_AFLAG_ADDRESS_VALID), &drive->atapi_flags))
                (void)idetape_rewind_tape(drive);
 
        /* Read block size and write protect status from drive. */
@@ -1584,7 +1519,7 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
        if (tape->write_prot) {
                if ((filp->f_flags & O_ACCMODE) == O_WRONLY ||
                    (filp->f_flags & O_ACCMODE) == O_RDWR) {
-                       clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
+                       clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
                        retval = -EROFS;
                        goto out_put_tape;
                }
@@ -1597,12 +1532,15 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp)
                                tape->door_locked = DOOR_LOCKED;
                }
        }
-       unlock_kernel();
+       mutex_unlock(&idetape_chrdev_mutex);
+
        return 0;
 
 out_put_tape:
        ide_tape_put(tape);
-       unlock_kernel();
+
+       mutex_unlock(&idetape_chrdev_mutex);
+
        return retval;
 }
 
@@ -1629,10 +1567,11 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
        ide_drive_t *drive = tape->drive;
        unsigned int minor = iminor(inode);
 
-       lock_kernel();
+       mutex_lock(&idetape_chrdev_mutex);
+
        tape = drive->driver_data;
 
-       debug_log(DBG_CHRDEV, "Enter %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "enter");
 
        if (tape->chrdev_dir == IDETAPE_DIR_WRITE)
                idetape_write_release(drive, minor);
@@ -1641,17 +1580,21 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp)
                        ide_tape_discard_merge_buffer(drive, 1);
        }
 
-       if (minor < 128 && test_bit(IDE_AFLAG_MEDIUM_PRESENT, &drive->atapi_flags))
+       if (minor < 128 && test_bit(ilog2(IDE_AFLAG_MEDIUM_PRESENT),
+                                   &drive->atapi_flags))
                (void) idetape_rewind_tape(drive);
+
        if (tape->chrdev_dir == IDETAPE_DIR_NONE) {
                if (tape->door_locked == DOOR_LOCKED) {
                        if (!ide_set_media_lock(drive, tape->disk, 0))
                                tape->door_locked = DOOR_UNLOCKED;
                }
        }
-       clear_bit(IDE_AFLAG_BUSY, &drive->atapi_flags);
+       clear_bit(ilog2(IDE_AFLAG_BUSY), &drive->atapi_flags);
        ide_tape_put(tape);
-       unlock_kernel();
+
+       mutex_unlock(&idetape_chrdev_mutex);
+
        return 0;
 }
 
@@ -1663,17 +1606,14 @@ static void idetape_get_inquiry_results(ide_drive_t *drive)
        char fw_rev[4], vendor_id[8], product_id[16];
 
        idetape_create_inquiry_cmd(&pc);
-       pc.buf = &pc_buf[0];
-       pc.buf_size = sizeof(pc_buf);
-
-       if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
+       if (ide_queue_pc_tail(drive, tape->disk, &pc, pc_buf, pc.req_xfer)) {
                printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n",
                                tape->name);
                return;
        }
-       memcpy(vendor_id, &pc.buf[8], 8);
-       memcpy(product_id, &pc.buf[16], 16);
-       memcpy(fw_rev, &pc.buf[32], 4);
+       memcpy(vendor_id, &pc_buf[8], 8);
+       memcpy(product_id, &pc_buf[16], 16);
+       memcpy(fw_rev, &pc_buf[32], 4);
 
        ide_fixstring(vendor_id, 8, 0);
        ide_fixstring(product_id, 16, 0);
@@ -1691,11 +1631,11 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        struct ide_atapi_pc pc;
-       u8 *caps;
+       u8 buf[24], *caps;
        u8 speed, max_speed;
 
        idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
-       if (ide_queue_pc_tail(drive, tape->disk, &pc)) {
+       if (ide_queue_pc_tail(drive, tape->disk, &pc, buf, pc.req_xfer)) {
                printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
                                " some default values\n");
                tape->blk_size = 512;
@@ -1704,7 +1644,7 @@ static void idetape_get_mode_sense_results(ide_drive_t *drive)
                put_unaligned(6*52, (u16 *)&tape->caps[16]);
                return;
        }
-       caps = pc.buf + 4 + pc.buf[3];
+       caps = buf + 4 + buf[3];
 
        /* convert to host order and save for later use */
        speed = be16_to_cpup((__be16 *)&caps[14]);
@@ -1770,7 +1710,6 @@ static int divf_buffer_size(ide_drive_t *drive)   { return 1024; }
 
 ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
 
-ide_tape_devset_rw_field(debug_mask, debug_mask);
 ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
 
 ide_tape_devset_r_field(avg_speed, avg_speed);
@@ -1782,7 +1721,6 @@ static const struct ide_proc_devset idetape_settings[] = {
        __IDE_PROC_DEVSET(avg_speed,    0, 0xffff, NULL, NULL),
        __IDE_PROC_DEVSET(buffer,       0, 0xffff, NULL, divf_buffer),
        __IDE_PROC_DEVSET(buffer_size,  0, 0xffff, NULL, divf_buffer_size),
-       __IDE_PROC_DEVSET(debug_mask,   0, 0xffff, NULL, NULL),
        __IDE_PROC_DEVSET(dsc_overlap,  0,      1, NULL, NULL),
        __IDE_PROC_DEVSET(speed,        0, 0xffff, NULL, NULL),
        __IDE_PROC_DEVSET(tdsc,         IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX,
@@ -1809,7 +1747,9 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
        int buffer_size;
        u16 *ctl = (u16 *)&tape->caps[12];
 
-       drive->pc_callback       = ide_tape_callback;
+       ide_debug_log(IDE_DBG_FUNC, "minor: %d", minor);
+
+       drive->pc_callback = ide_tape_callback;
 
        drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
 
@@ -1896,22 +1836,32 @@ static void ide_tape_release(struct device *dev)
 }
 
 #ifdef CONFIG_IDE_PROC_FS
-static int proc_idetape_read_name
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+static int idetape_name_proc_show(struct seq_file *m, void *v)
 {
-       ide_drive_t     *drive = (ide_drive_t *) data;
+       ide_drive_t     *drive = (ide_drive_t *) m->private;
        idetape_tape_t  *tape = drive->driver_data;
-       char            *out = page;
-       int             len;
 
-       len = sprintf(out, "%s\n", tape->name);
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+       seq_printf(m, "%s\n", tape->name);
+       return 0;
+}
+
+static int idetape_name_proc_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, idetape_name_proc_show, PDE(inode)->data);
 }
 
+static const struct file_operations idetape_name_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = idetape_name_proc_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 static ide_proc_entry_t idetape_proc[] = {
-       { "capacity",   S_IFREG|S_IRUGO,        proc_ide_read_capacity, NULL },
-       { "name",       S_IFREG|S_IRUGO,        proc_idetape_read_name, NULL },
-       { NULL, 0, NULL, NULL }
+       { "capacity",   S_IFREG|S_IRUGO,        &ide_capacity_proc_fops },
+       { "name",       S_IFREG|S_IRUGO,        &idetape_name_proc_fops },
+       {}
 };
 
 static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
@@ -1948,14 +1898,14 @@ static const struct file_operations idetape_fops = {
        .owner          = THIS_MODULE,
        .read           = idetape_chrdev_read,
        .write          = idetape_chrdev_write,
-       .ioctl          = idetape_chrdev_ioctl,
+       .unlocked_ioctl = idetape_chrdev_ioctl,
        .open           = idetape_chrdev_open,
        .release        = idetape_chrdev_release,
 };
 
 static int idetape_open(struct block_device *bdev, fmode_t mode)
 {
-       struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk);
+       struct ide_tape_obj *tape = ide_tape_get(bdev->bd_disk, false, 0);
 
        if (!tape)
                return -ENXIO;
@@ -1982,7 +1932,7 @@ static int idetape_ioctl(struct block_device *bdev, fmode_t mode,
        return err;
 }
 
-static struct block_device_operations idetape_block_ops = {
+static const struct block_device_operations idetape_block_ops = {
        .owner          = THIS_MODULE,
        .open           = idetape_open,
        .release        = idetape_release,
@@ -1995,7 +1945,9 @@ static int ide_tape_probe(ide_drive_t *drive)
        struct gendisk *g;
        int minor;
 
-       if (!strstr("ide-tape", drive->driver_req))
+       ide_debug_log(IDE_DBG_FUNC, "enter");
+
+       if (!strstr(DRV_NAME, drive->driver_req))
                goto failed;
 
        if (drive->media != ide_tape)