Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[pandora-kernel.git] / drivers / ide / ide-tape.c
index 32f56ee..bf40d8c 100644 (file)
 #include <linux/completion.h>
 #include <linux/bitops.h>
 #include <linux/mutex.h>
+#include <scsi/scsi.h>
 
 #include <asm/byteorder.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/unaligned.h>
-
-/*
- * partition
- */
-typedef struct os_partition_s {
-       __u8    partition_num;
-       __u8    par_desc_ver;
-       __u16   wrt_pass_cntr;
-       __u32   first_frame_addr;
-       __u32   last_frame_addr;
-       __u32   eod_frame_addr;
-} os_partition_t;
-
-/*
- * DAT entry
- */
-typedef struct os_dat_entry_s {
-       __u32   blk_sz;
-       __u16   blk_cnt;
-       __u8    flags;
-       __u8    reserved;
-} os_dat_entry_t;
-
-/*
- * DAT
- */
-#define OS_DAT_FLAGS_DATA      (0xc)
-#define OS_DAT_FLAGS_MARK      (0x1)
-
-typedef struct os_dat_s {
-       __u8            dat_sz;
-       __u8            reserved1;
-       __u8            entry_cnt;
-       __u8            reserved3;
-       os_dat_entry_t  dat_list[16];
-} os_dat_t;
-
 #include <linux/mtio.h>
 
 /**************************** Tunable parameters *****************************/
@@ -259,24 +223,6 @@ typedef struct idetape_packet_command_s {
 /* Data direction */
 #define        PC_WRITING                      5
 
-/*
- *     Block Size Page
- */
-typedef struct {
-       unsigned        page_code       :6;     /* Page code - Should be 0x30 */
-       unsigned        reserved1_6     :1;
-       unsigned        ps              :1;
-       __u8            page_length;            /* Page Length - Should be 2 */
-       __u8            reserved2;
-       unsigned        play32          :1;
-       unsigned        play32_5        :1;
-       unsigned        reserved2_23    :2;
-       unsigned        record32        :1;
-       unsigned        record32_5      :1;
-       unsigned        reserved2_6     :1;
-       unsigned        one             :1;
-} idetape_block_size_page_t;
-
 /*
  *     A pipeline stage.
  */
@@ -571,27 +517,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
 /* 0 = no tape is loaded, so we don't rewind after ejecting */
 #define IDETAPE_MEDIUM_PRESENT         9
 
-/*
- *     Supported ATAPI tape drives packet commands
- */
-#define IDETAPE_TEST_UNIT_READY_CMD    0x00
-#define IDETAPE_REWIND_CMD             0x01
-#define IDETAPE_REQUEST_SENSE_CMD      0x03
-#define IDETAPE_READ_CMD               0x08
-#define IDETAPE_WRITE_CMD              0x0a
-#define IDETAPE_WRITE_FILEMARK_CMD     0x10
-#define IDETAPE_SPACE_CMD              0x11
-#define IDETAPE_INQUIRY_CMD            0x12
-#define IDETAPE_ERASE_CMD              0x19
-#define IDETAPE_MODE_SENSE_CMD         0x1a
-#define IDETAPE_MODE_SELECT_CMD                0x15
-#define IDETAPE_LOAD_UNLOAD_CMD                0x1b
-#define IDETAPE_PREVENT_CMD            0x1e
-#define IDETAPE_LOCATE_CMD             0x2b
-#define IDETAPE_READ_POSITION_CMD      0x34
-#define IDETAPE_READ_BUFFER_CMD                0x3c
-#define IDETAPE_SET_SPEED_CMD          0xbb
-
 /*
  *     Some defines for the READ BUFFER command
  */
@@ -666,37 +591,9 @@ typedef struct {
        u32             bytes_in_buffer;        /* Bytes In Buffer (Optional) */
 } idetape_read_position_result_t;
 
-/*
- *     Follows structures which are related to the SELECT SENSE / MODE SENSE
- *     packet commands. Those packet commands are still not supported
- *     by ide-tape.
- */
+/* Structures related to the SELECT SENSE / MODE SENSE packet commands. */
 #define IDETAPE_BLOCK_DESCRIPTOR       0
 #define        IDETAPE_CAPABILITIES_PAGE       0x2a
-#define IDETAPE_PARAMTR_PAGE           0x2b   /* Onstream DI-x0 only */
-#define IDETAPE_BLOCK_SIZE_PAGE                0x30
-#define IDETAPE_BUFFER_FILLING_PAGE    0x33
-
-/*
- *     Mode Parameter Block Descriptor the MODE SENSE packet command
- *
- *     Support for block descriptors is optional.
- */
-typedef struct {
-       __u8            density_code;           /* Medium density code */
-       __u8            blocks[3];              /* Number of blocks */
-       __u8            reserved4;              /* Reserved */
-       __u8            length[3];              /* Block Length */
-} idetape_parameter_block_descriptor_t;
-
-/*
- *     Run time configurable parameters.
- */
-typedef struct {
-       int     dsc_rw_frequency;
-       int     dsc_media_access_frequency;
-       int     nr_stages;
-} idetape_config_t;
 
 /*
  *     The variables below are used for the character device interface.
@@ -899,7 +796,7 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
        if (test_bit(PC_DMA_ERROR, &pc->flags)) {
                pc->actually_transferred = pc->request_transfer -
                        tape->tape_block_size *
-                       ntohl(get_unaligned((u32 *)&sense[3]));
+                       be32_to_cpu(get_unaligned((u32 *)&sense[3]));
                idetape_update_buffers(pc);
        }
 
@@ -908,7 +805,7 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
         * with sense key=5, asc=0x22, ascq=0, let it slide.  Some drives
         * (i.e. Seagate STT3401A Travan) don't support 0-length read/writes.
         */
-       if ((pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD)
+       if ((pc->c[0] == READ_6 || pc->c[0] == WRITE_6)
            /* length == 0 */
            && pc->c[4] == 0 && pc->c[3] == 0 && pc->c[2] == 0) {
                if (tape->sense_key == 5) {
@@ -918,18 +815,18 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
                        set_bit(PC_ABORT, &pc->flags);
                }
        }
-       if (pc->c[0] == IDETAPE_READ_CMD && (sense[2] & 0x80)) {
+       if (pc->c[0] == READ_6 && (sense[2] & 0x80)) {
                pc->error = IDETAPE_ERROR_FILEMARK;
                set_bit(PC_ABORT, &pc->flags);
        }
-       if (pc->c[0] == IDETAPE_WRITE_CMD) {
+       if (pc->c[0] == WRITE_6) {
                if ((sense[2] & 0x40) || (tape->sense_key == 0xd
                     && tape->asc == 0x0 && tape->ascq == 0x2)) {
                        pc->error = IDETAPE_ERROR_EOD;
                        set_bit(PC_ABORT, &pc->flags);
                }
        }
-       if (pc->c[0] == IDETAPE_READ_CMD || pc->c[0] == IDETAPE_WRITE_CMD) {
+       if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
                if (tape->sense_key == 8) {
                        pc->error = IDETAPE_ERROR_EOD;
                        set_bit(PC_ABORT, &pc->flags);
@@ -940,10 +837,7 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
        }
 }
 
-/*
- * idetape_active_next_stage will declare the next stage as "active".
- */
-static void idetape_active_next_stage (ide_drive_t *drive)
+static void idetape_activate_next_stage(ide_drive_t *drive)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_stage_t *stage = tape->next_stage;
@@ -1134,7 +1028,7 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
                        }
                }
                if (tape->next_stage != NULL) {
-                       idetape_active_next_stage(drive);
+                       idetape_activate_next_stage(drive);
 
                        /*
                         * Insert the next request into the request queue.
@@ -1178,7 +1072,7 @@ static ide_startstop_t idetape_request_sense_callback (ide_drive_t *drive)
 static void idetape_create_request_sense_cmd (idetape_pc_t *pc)
 {
        idetape_init_pc(pc);    
-       pc->c[0] = IDETAPE_REQUEST_SENSE_CMD;
+       pc->c[0] = REQUEST_SENSE;
        pc->c[4] = 20;
        pc->request_transfer = 20;
        pc->callback = &idetape_request_sense_callback;
@@ -1331,15 +1225,14 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
                local_irq_enable();
 
 #if SIMULATE_ERRORS
-               if ((pc->c[0] == IDETAPE_WRITE_CMD ||
-                    pc->c[0] == IDETAPE_READ_CMD) &&
+               if ((pc->c[0] == WRITE_6 || pc->c[0] == READ_6) &&
                    (++error_sim_count % 100) == 0) {
                        printk(KERN_INFO "ide-tape: %s: simulating error\n",
                                tape->name);
                        stat |= ERR_STAT;
                }
 #endif
-               if ((stat & ERR_STAT) && pc->c[0] == IDETAPE_REQUEST_SENSE_CMD)
+               if ((stat & ERR_STAT) && pc->c[0] == REQUEST_SENSE)
                        stat &= ~ERR_STAT;
                if ((stat & ERR_STAT) || test_bit(PC_DMA_ERROR, &pc->flags)) {
                        /* Error detected */
@@ -1348,7 +1241,7 @@ static ide_startstop_t idetape_pc_intr (ide_drive_t *drive)
                                printk(KERN_INFO "ide-tape: %s: I/O error\n",
                                        tape->name);
 #endif /* IDETAPE_DEBUG_LOG */
-                       if (pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
+                       if (pc->c[0] == REQUEST_SENSE) {
                                printk(KERN_ERR "ide-tape: I/O error in request sense command\n");
                                return ide_do_reset(drive);
                        }
@@ -1536,13 +1429,13 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
        int dma_ok = 0;
        u16 bcount;
 
-       if (tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD &&
-           pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
+       if (tape->pc->c[0] == REQUEST_SENSE &&
+           pc->c[0] == REQUEST_SENSE) {
                printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
                        "Two request sense in serial were issued\n");
        }
 
-       if (tape->failed_pc == NULL && pc->c[0] != IDETAPE_REQUEST_SENSE_CMD)
+       if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
                tape->failed_pc = pc;
        /* Set the current packet command */
        tape->pc = pc;
@@ -1555,7 +1448,7 @@ static ide_startstop_t idetape_issue_packet_command (ide_drive_t *drive, idetape
                 *      filemark, or end of the media, for example).
                 */
                if (!test_bit(PC_ABORT, &pc->flags)) {
-                       if (!(pc->c[0] == IDETAPE_TEST_UNIT_READY_CMD &&
+                       if (!(pc->c[0] == TEST_UNIT_READY &&
                              tape->sense_key == 2 && tape->asc == 4 &&
                             (tape->ascq == 1 || tape->ascq == 8))) {
                                printk(KERN_ERR "ide-tape: %s: I/O error, "
@@ -1628,7 +1521,7 @@ static ide_startstop_t idetape_pc_callback (ide_drive_t *drive)
 static void idetape_create_mode_sense_cmd (idetape_pc_t *pc, u8 page_code)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_MODE_SENSE_CMD;
+       pc->c[0] = MODE_SENSE;
        if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
                pc->c[1] = 8;   /* DBD = 1 - Don't return block descriptors */
        pc->c[2] = page_code;
@@ -1709,7 +1602,7 @@ static ide_startstop_t idetape_media_access_finished (ide_drive_t *drive)
        if (stat & SEEK_STAT) {
                if (stat & ERR_STAT) {
                        /* Error detected */
-                       if (pc->c[0] != IDETAPE_TEST_UNIT_READY_CMD)
+                       if (pc->c[0] != TEST_UNIT_READY)
                                printk(KERN_ERR "ide-tape: %s: I/O error, ",
                                                tape->name);
                        /* Retry operation */
@@ -1766,8 +1659,8 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
 static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_CMD;
-       put_unaligned(htonl(length), (unsigned int *) &pc->c[1]);
+       pc->c[0] = READ_6;
+       put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
        pc->callback = &idetape_rw_callback;
        pc->bh = bh;
@@ -1784,7 +1677,7 @@ static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *p
        struct idetape_bh *p = bh;
 
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_BUFFER_CMD;
+       pc->c[0] = READ_BUFFER;
        pc->c[1] = IDETAPE_RETRIEVE_FAULTY_BLOCK;
        pc->c[7] = size >> 8;
        pc->c[8] = size & 0xff;
@@ -1802,8 +1695,8 @@ static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *p
 static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_WRITE_CMD;
-       put_unaligned(htonl(length), (unsigned int *) &pc->c[1]);
+       pc->c[0] = WRITE_6;
+       put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
        pc->c[1] = 1;
        pc->callback = &idetape_rw_callback;
        set_bit(PC_WRITING, &pc->flags);
@@ -1848,7 +1741,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
         *      Retry a failed packet command
         */
        if (tape->failed_pc != NULL &&
-           tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
+           tape->pc->c[0] == REQUEST_SENSE) {
                return idetape_issue_packet_command(drive, tape->failed_pc);
        }
        if (postponed_rq != NULL)
@@ -2219,7 +2112,7 @@ static ide_startstop_t idetape_read_position_callback (ide_drive_t *drive)
 static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t *pc,int write_filemark)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_WRITE_FILEMARK_CMD;
+       pc->c[0] = WRITE_FILEMARKS;
        pc->c[4] = write_filemark;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2228,7 +2121,7 @@ static void idetape_create_write_filemark_cmd (ide_drive_t *drive, idetape_pc_t
 static void idetape_create_test_unit_ready_cmd(idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_TEST_UNIT_READY_CMD;
+       pc->c[0] = TEST_UNIT_READY;
        pc->callback = &idetape_pc_callback;
 }
 
@@ -2266,7 +2159,7 @@ static int __idetape_queue_pc_tail (ide_drive_t *drive, idetape_pc_t *pc)
 static void idetape_create_load_unload_cmd (ide_drive_t *drive, idetape_pc_t *pc,int cmd)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_LOAD_UNLOAD_CMD;
+       pc->c[0] = START_STOP;
        pc->c[4] = cmd;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2323,7 +2216,7 @@ static int idetape_flush_tape_buffers (ide_drive_t *drive)
 static void idetape_create_read_position_cmd (idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_READ_POSITION_CMD;
+       pc->c[0] = READ_POSITION;
        pc->request_transfer = 20;
        pc->callback = &idetape_read_position_callback;
 }
@@ -2349,9 +2242,9 @@ static int idetape_read_position (ide_drive_t *drive)
 static void idetape_create_locate_cmd (ide_drive_t *drive, idetape_pc_t *pc, unsigned int block, u8 partition, int skip)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_LOCATE_CMD;
+       pc->c[0] = POSITION_TO_ELEMENT;
        pc->c[1] = 2;
-       put_unaligned(htonl(block), (unsigned int *) &pc->c[3]);
+       put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
        pc->c[8] = partition;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2366,7 +2259,7 @@ static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int
                return 0;
 
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_PREVENT_CMD;
+       pc->c[0] = ALLOW_MEDIUM_REMOVAL;
        pc->c[4] = prevent;
        pc->callback = &idetape_pc_callback;
        return 1;
@@ -2509,7 +2402,7 @@ static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
                return;
        if (!idetape_pipeline_active(tape)) {
                set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
-               idetape_active_next_stage(drive);
+               idetape_activate_next_stage(drive);
                (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end);
        }
 }
@@ -2517,7 +2410,7 @@ static void idetape_insert_pipeline_into_queue (ide_drive_t *drive)
 static void idetape_create_inquiry_cmd (idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_INQUIRY_CMD;
+       pc->c[0] = INQUIRY;
        pc->c[4] = pc->request_transfer = 254;
        pc->callback = &idetape_pc_callback;
 }
@@ -2525,7 +2418,7 @@ static void idetape_create_inquiry_cmd (idetape_pc_t *pc)
 static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_REWIND_CMD;
+       pc->c[0] = REZERO_UNIT;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
 }
@@ -2533,7 +2426,7 @@ static void idetape_create_rewind_cmd (ide_drive_t *drive, idetape_pc_t *pc)
 static void idetape_create_erase_cmd (idetape_pc_t *pc)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_ERASE_CMD;
+       pc->c[0] = ERASE;
        pc->c[1] = 1;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2542,8 +2435,8 @@ static void idetape_create_erase_cmd (idetape_pc_t *pc)
 static void idetape_create_space_cmd (idetape_pc_t *pc,int count, u8 cmd)
 {
        idetape_init_pc(pc);
-       pc->c[0] = IDETAPE_SPACE_CMD;
-       put_unaligned(htonl(count), (unsigned int *) &pc->c[1]);
+       pc->c[0] = SPACE;
+       put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
        pc->c[1] = cmd;
        set_bit(PC_WAIT_FOR_DSC, &pc->flags);
        pc->callback = &idetape_pc_callback;
@@ -2947,16 +2840,21 @@ static int idetape_rewind_tape (ide_drive_t *drive)
 static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned long arg)
 {
        idetape_tape_t *tape = drive->driver_data;
-       idetape_config_t config;
        void __user *argp = (void __user *)arg;
 
+       struct idetape_config {
+               int dsc_rw_frequency;
+               int dsc_media_access_frequency;
+               int nr_stages;
+       } config;
+
 #if IDETAPE_DEBUG_LOG  
        if (tape->debug_level >= 4)
                printk(KERN_INFO "ide-tape: Reached idetape_blkdev_ioctl\n");
 #endif /* IDETAPE_DEBUG_LOG */
        switch (cmd) {
                case 0x0340:
-                       if (copy_from_user(&config, argp, sizeof (idetape_config_t)))
+                       if (copy_from_user(&config, argp, sizeof(config)))
                                return -EFAULT;
                        tape->best_dsc_rw_frequency = config.dsc_rw_frequency;
                        tape->max_stages = config.nr_stages;
@@ -2964,7 +2862,7 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, unsigned l
                case 0x0350:
                        config.dsc_rw_frequency = (int) tape->best_dsc_rw_frequency;
                        config.nr_stages = tape->max_stages; 
-                       if (copy_to_user(argp, &config, sizeof (idetape_config_t)))
+                       if (copy_to_user(argp, &config, sizeof(config)))
                                return -EFAULT;
                        break;
                default:
@@ -3250,69 +3148,20 @@ static int idetape_write_filemark (ide_drive_t *drive)
 }
 
 /*
- *     idetape_mtioctop is called from idetape_chrdev_ioctl when
- *     the general mtio MTIOCTOP ioctl is requested.
- *
- *     We currently support the following mtio.h operations:
- *
- *     MTFSF   -       Space over mt_count filemarks in the positive direction.
- *                     The tape is positioned after the last spaced filemark.
- *
- *     MTFSFM  -       Same as MTFSF, but the tape is positioned before the
- *                     last filemark.
- *
- *     MTBSF   -       Steps background over mt_count filemarks, tape is
- *                     positioned before the last filemark.
- *
- *     MTBSFM  -       Like MTBSF, only tape is positioned after the last filemark.
- *
- *     Note:
- *
- *             MTBSF and MTBSFM are not supported when the tape doesn't
- *             support spacing over filemarks in the reverse direction.
- *             In this case, MTFSFM is also usually not supported (it is
- *             supported in the rare case in which we crossed the filemark
- *             during our read-ahead pipelined operation mode).
- *             
- *     MTWEOF  -       Writes mt_count filemarks. Tape is positioned after
- *                     the last written filemark.
- *
- *     MTREW   -       Rewinds tape.
- *
- *     MTLOAD  -       Loads the tape.
- *
- *     MTOFFL  -       Puts the tape drive "Offline": Rewinds the tape and
- *     MTUNLOAD        prevents further access until the media is replaced.
- *
- *     MTNOP   -       Flushes tape buffers.
- *
- *     MTRETEN -       Retension media. This typically consists of one end
- *                     to end pass on the media.
- *
- *     MTEOM   -       Moves to the end of recorded data.
+ * Called from idetape_chrdev_ioctl when the general mtio MTIOCTOP ioctl is
+ * requested.
  *
- *     MTERASE -       Erases tape.
+ * Note: MTBSF and MTBSFM are not supported when the tape doesn't support
+ * spacing over filemarks in the reverse direction. In this case, MTFSFM is also
+ * usually not supported (it is supported in the rare case in which we crossed
+ * the filemark during our read-ahead pipelined operation mode).
  *
- *     MTSETBLK -      Sets the user block size to mt_count bytes. If
- *                     mt_count is 0, we will attempt to autodetect
- *                     the block size.
+ * The following commands are currently not supported:
  *
- *     MTSEEK  -       Positions the tape in a specific block number, where
- *                     each block is assumed to contain which user_block_size
- *                     bytes.
- *
- *     MTSETPART -     Switches to another tape partition.
- *
- *     MTLOCK -        Locks the tape door.
- *
- *     MTUNLOCK -      Unlocks the tape door.
- *
- *     The following commands are currently not supported:
- *
- *     MTFSS, MTBSS, MTWSM, MTSETDENSITY,
- *     MTSETDRVBUFFER, MT_ST_BOOLEANS, MT_ST_WRITE_THRESHOLD.
+ * MTFSS, MTBSS, MTWSM, MTSETDENSITY, MTSETDRVBUFFER, MT_ST_BOOLEANS,
+ * MT_ST_WRITE_THRESHOLD.
  */
-static int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
+static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
 {
        idetape_tape_t *tape = drive->driver_data;
        idetape_pc_t pc;
@@ -3427,29 +3276,12 @@ static int idetape_mtioctop (ide_drive_t *drive,short mt_op,int mt_count)
 }
 
 /*
- *     Our character device ioctls.
- *
- *     General mtio.h magnetic io commands are supported here, and not in
- *     the corresponding block interface.
- *
- *     The following ioctls are supported:
- *
- *     MTIOCTOP -      Refer to idetape_mtioctop for detailed description.
- *
- *     MTIOCGET -      The mt_dsreg field in the returned mtget structure
- *                     will be set to (user block size in bytes <<
- *                     MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK.
- *
- *                     The mt_blkno is set to the current user block number.
- *                     The other mtget fields are not supported.
- *
- *     MTIOCPOS -      The current tape "block position" is returned. We
- *                     assume that each block contains user_block_size
- *                     bytes.
- *
- *     Our own ide-tape ioctls are supported on both interfaces.
+ * Our character device ioctls. General mtio.h magnetic io commands are
+ * 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, unsigned int cmd, unsigned long arg)
+static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
+                               unsigned int cmd, unsigned long arg)
 {
        struct ide_tape_obj *tape = ide_tape_f(file);
        ide_drive_t *drive = tape->drive;
@@ -3503,7 +3335,30 @@ static int idetape_chrdev_ioctl (struct inode *inode, struct file *file, unsigne
        }
 }
 
-static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive);
+/*
+ * Do a mode sense page 0 with block descriptor and if it succeeds set the tape
+ * block size with the reported value.
+ */
+static void ide_tape_get_bsize_from_bdesc(ide_drive_t *drive)
+{
+       idetape_tape_t *tape = drive->driver_data;
+       idetape_pc_t pc;
+
+       idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
+       if (idetape_queue_pc_tail(drive, &pc)) {
+               printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
+               if (tape->tape_block_size == 0) {
+                       printk(KERN_WARNING "ide-tape: Cannot deal with zero "
+                                           "block size, assuming 32k\n");
+                       tape->tape_block_size = 32768;
+               }
+               return;
+       }
+       tape->tape_block_size = (pc.buffer[4 + 5] << 16) +
+                               (pc.buffer[4 + 6] << 8)  +
+                                pc.buffer[4 + 7];
+       tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7;
+}
 
 /*
  *     Our character device open function.
@@ -3557,7 +3412,7 @@ static int idetape_chrdev_open (struct inode *inode, struct file *filp)
                clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
 
        /* Read block size and write protect status from drive. */
-       idetape_get_blocksize_from_block_descriptor(drive);
+       ide_tape_get_bsize_from_bdesc(drive);
 
        /* Set write protect flag if device is opened as read-only. */
        if ((filp->f_flags & O_ACCMODE) == O_RDONLY)
@@ -3771,31 +3626,6 @@ static void idetape_get_mode_sense_results (ide_drive_t *drive)
                tape->tape_block_size = 1024;
 }
 
-/*
- *     ide_get_blocksize_from_block_descriptor does a mode sense page 0 with block descriptor
- *     and if it succeeds sets the tape block size with the reported value
- */
-static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive)
-{
-
-       idetape_tape_t *tape = drive->driver_data;
-       idetape_pc_t pc;
-       idetape_parameter_block_descriptor_t *block_descrp;
-
-       idetape_create_mode_sense_cmd(&pc, IDETAPE_BLOCK_DESCRIPTOR);
-       if (idetape_queue_pc_tail(drive, &pc)) {
-               printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
-               if (tape->tape_block_size == 0) {
-                       printk(KERN_WARNING "ide-tape: Cannot deal with zero block size, assume 32k\n");
-                       tape->tape_block_size =  32768;
-               }
-               return;
-       }
-       block_descrp = (idetape_parameter_block_descriptor_t *)(pc.buffer + 4);
-       tape->tape_block_size =( block_descrp->length[0]<<16) + (block_descrp->length[1]<<8) + block_descrp->length[2];
-       tape->drv_write_prot = (pc.buffer[2] & 0x80) >> 7;
-}
-
 #ifdef CONFIG_IDE_PROC_FS
 static void idetape_add_settings (ide_drive_t *drive)
 {
@@ -3872,7 +3702,7 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
        
        idetape_get_inquiry_results(drive);
        idetape_get_mode_sense_results(drive);
-       idetape_get_blocksize_from_block_descriptor(drive);
+       ide_tape_get_bsize_from_bdesc(drive);
        tape->user_bs_factor = 1;
        tape->stage_size = *ctl * tape->tape_block_size;
        while (tape->stage_size > 0xffff) {