aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c142
1 files changed, 56 insertions, 86 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 3d15e8e729ef..6fa6a38d8116 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -260,47 +260,6 @@ typedef struct idetape_packet_command_s {
260#define PC_WRITING 5 260#define PC_WRITING 5
261 261
262/* 262/*
263 * Capabilities and Mechanical Status Page
264 */
265typedef struct {
266 unsigned page_code :6; /* Page code - Should be 0x2a */
267 __u8 reserved0_6 :1;
268 __u8 ps :1; /* parameters saveable */
269 __u8 page_length; /* Page Length - Should be 0x12 */
270 __u8 reserved2, reserved3;
271 unsigned ro :1; /* Read Only Mode */
272 unsigned reserved4_1234 :4;
273 unsigned sprev :1; /* Supports SPACE in the reverse direction */
274 unsigned reserved4_67 :2;
275 unsigned reserved5_012 :3;
276 unsigned efmt :1; /* Supports ERASE command initiated formatting */
277 unsigned reserved5_4 :1;
278 unsigned qfa :1; /* Supports the QFA two partition formats */
279 unsigned reserved5_67 :2;
280 unsigned lock :1; /* Supports locking the volume */
281 unsigned locked :1; /* The volume is locked */
282 unsigned prevent :1; /* The device defaults in the prevent state after power up */
283 unsigned eject :1; /* The device can eject the volume */
284 __u8 disconnect :1; /* The device can break request > ctl */
285 __u8 reserved6_5 :1;
286 unsigned ecc :1; /* Supports error correction */
287 unsigned cmprs :1; /* Supports data compression */
288 unsigned reserved7_0 :1;
289 unsigned blk512 :1; /* Supports 512 bytes block size */
290 unsigned blk1024 :1; /* Supports 1024 bytes block size */
291 unsigned reserved7_3_6 :4;
292 unsigned blk32768 :1; /* slowb - the device restricts the byte count for PIO */
293 /* transfers for slow buffer memory ??? */
294 /* Also 32768 block size in some cases */
295 __u16 max_speed; /* Maximum speed supported in KBps */
296 __u8 reserved10, reserved11;
297 __u16 ctl; /* Continuous Transfer Limit in blocks */
298 __u16 speed; /* Current Speed, in KBps */
299 __u16 buffer_size; /* Buffer Size, in 512 bytes */
300 __u8 reserved18, reserved19;
301} idetape_capabilities_page_t;
302
303/*
304 * Block Size Page 263 * Block Size Page
305 */ 264 */
306typedef struct { 265typedef struct {
@@ -417,8 +376,9 @@ typedef struct ide_tape_obj {
417 /* Usually 512 or 1024 bytes */ 376 /* Usually 512 or 1024 bytes */
418 unsigned short tape_block_size; 377 unsigned short tape_block_size;
419 int user_bs_factor; 378 int user_bs_factor;
379
420 /* Copy of the tape's Capabilities and Mechanical Page */ 380 /* Copy of the tape's Capabilities and Mechanical Page */
421 idetape_capabilities_page_t capabilities; 381 u8 caps[20];
422 382
423 /* 383 /*
424 * Active data transfer request parameters. 384 * Active data transfer request parameters.
@@ -2464,7 +2424,8 @@ static int idetape_create_prevent_cmd (ide_drive_t *drive, idetape_pc_t *pc, int
2464{ 2424{
2465 idetape_tape_t *tape = drive->driver_data; 2425 idetape_tape_t *tape = drive->driver_data;
2466 2426
2467 if (!tape->capabilities.lock) 2427 /* device supports locking according to capabilities page */
2428 if (!(tape->caps[6] & 0x01))
2468 return 0; 2429 return 0;
2469 2430
2470 idetape_init_pc(pc); 2431 idetape_init_pc(pc);
@@ -2850,7 +2811,7 @@ static int idetape_initiate_read (ide_drive_t *drive, int max_stages)
2850 idetape_stage_t *new_stage; 2811 idetape_stage_t *new_stage;
2851 struct request rq; 2812 struct request rq;
2852 int bytes_read; 2813 int bytes_read;
2853 int blocks = tape->capabilities.ctl; 2814 u16 blocks = *(u16 *)&tape->caps[12];
2854 2815
2855 /* Initialize read operation */ 2816 /* Initialize read operation */
2856 if (tape->chrdev_direction != idetape_direction_read) { 2817 if (tape->chrdev_direction != idetape_direction_read) {
@@ -3090,11 +3051,12 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
3090 idetape_pc_t pc; 3051 idetape_pc_t pc;
3091 unsigned long flags; 3052 unsigned long flags;
3092 int retval,count=0; 3053 int retval,count=0;
3054 int sprev = !!(tape->caps[4] & 0x20);
3093 3055
3094 if (mt_count == 0) 3056 if (mt_count == 0)
3095 return 0; 3057 return 0;
3096 if (MTBSF == mt_op || MTBSFM == mt_op) { 3058 if (MTBSF == mt_op || MTBSFM == mt_op) {
3097 if (!tape->capabilities.sprev) 3059 if (!sprev)
3098 return -EIO; 3060 return -EIO;
3099 mt_count = - mt_count; 3061 mt_count = - mt_count;
3100 } 3062 }
@@ -3148,7 +3110,7 @@ static int idetape_space_over_filemarks (ide_drive_t *drive,short mt_op,int mt_c
3148 return (idetape_queue_pc_tail(drive, &pc)); 3110 return (idetape_queue_pc_tail(drive, &pc));
3149 case MTFSFM: 3111 case MTFSFM:
3150 case MTBSFM: 3112 case MTBSFM:
3151 if (!tape->capabilities.sprev) 3113 if (!sprev)
3152 return (-EIO); 3114 return (-EIO);
3153 retval = idetape_space_over_filemarks(drive, MTFSF, mt_count-count); 3115 retval = idetape_space_over_filemarks(drive, MTFSF, mt_count-count);
3154 if (retval) return (retval); 3116 if (retval) return (retval);
@@ -3185,6 +3147,7 @@ static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
3185 ide_drive_t *drive = tape->drive; 3147 ide_drive_t *drive = tape->drive;
3186 ssize_t bytes_read,temp, actually_read = 0, rc; 3148 ssize_t bytes_read,temp, actually_read = 0, rc;
3187 ssize_t ret = 0; 3149 ssize_t ret = 0;
3150 u16 ctl = *(u16 *)&tape->caps[12];
3188 3151
3189#if IDETAPE_DEBUG_LOG 3152#if IDETAPE_DEBUG_LOG
3190 if (tape->debug_level >= 3) 3153 if (tape->debug_level >= 3)
@@ -3210,7 +3173,7 @@ static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
3210 count -= actually_read; 3173 count -= actually_read;
3211 } 3174 }
3212 while (count >= tape->stage_size) { 3175 while (count >= tape->stage_size) {
3213 bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl); 3176 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
3214 if (bytes_read <= 0) 3177 if (bytes_read <= 0)
3215 goto finish; 3178 goto finish;
3216 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read)) 3179 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read))
@@ -3220,7 +3183,7 @@ static ssize_t idetape_chrdev_read (struct file *file, char __user *buf,
3220 actually_read += bytes_read; 3183 actually_read += bytes_read;
3221 } 3184 }
3222 if (count) { 3185 if (count) {
3223 bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl); 3186 bytes_read = idetape_add_chrdev_read_request(drive, ctl);
3224 if (bytes_read <= 0) 3187 if (bytes_read <= 0)
3225 goto finish; 3188 goto finish;
3226 temp = min((unsigned long)count, (unsigned long)bytes_read); 3189 temp = min((unsigned long)count, (unsigned long)bytes_read);
@@ -3249,6 +3212,7 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3249 ide_drive_t *drive = tape->drive; 3212 ide_drive_t *drive = tape->drive;
3250 ssize_t actually_written = 0; 3213 ssize_t actually_written = 0;
3251 ssize_t ret = 0; 3214 ssize_t ret = 0;
3215 u16 ctl = *(u16 *)&tape->caps[12];
3252 3216
3253 /* The drive is write protected. */ 3217 /* The drive is write protected. */
3254 if (tape->write_prot) 3218 if (tape->write_prot)
@@ -3310,7 +3274,7 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3310 if (tape->merge_stage_size == tape->stage_size) { 3274 if (tape->merge_stage_size == tape->stage_size) {
3311 ssize_t retval; 3275 ssize_t retval;
3312 tape->merge_stage_size = 0; 3276 tape->merge_stage_size = 0;
3313 retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl); 3277 retval = idetape_add_chrdev_write_request(drive, ctl);
3314 if (retval <= 0) 3278 if (retval <= 0)
3315 return (retval); 3279 return (retval);
3316 } 3280 }
@@ -3321,7 +3285,7 @@ static ssize_t idetape_chrdev_write (struct file *file, const char __user *buf,
3321 ret = -EFAULT; 3285 ret = -EFAULT;
3322 buf += tape->stage_size; 3286 buf += tape->stage_size;
3323 count -= tape->stage_size; 3287 count -= tape->stage_size;
3324 retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl); 3288 retval = idetape_add_chrdev_write_request(drive, ctl);
3325 actually_written += tape->stage_size; 3289 actually_written += tape->stage_size;
3326 if (retval <= 0) 3290 if (retval <= 0)
3327 return (retval); 3291 return (retval);
@@ -3821,46 +3785,52 @@ static void idetape_get_inquiry_results (ide_drive_t *drive)
3821} 3785}
3822 3786
3823/* 3787/*
3824 * idetape_get_mode_sense_results asks the tape about its various 3788 * Ask the tape about its various parameters. In particular, we will adjust our
3825 * parameters. In particular, we will adjust our data transfer buffer 3789 * data transfer buffer size to the recommended value as returned by the tape.
3826 * size to the recommended value as returned by the tape.
3827 */ 3790 */
3828static void idetape_get_mode_sense_results (ide_drive_t *drive) 3791static void idetape_get_mode_sense_results (ide_drive_t *drive)
3829{ 3792{
3830 idetape_tape_t *tape = drive->driver_data; 3793 idetape_tape_t *tape = drive->driver_data;
3831 idetape_pc_t pc; 3794 idetape_pc_t pc;
3832 idetape_capabilities_page_t *capabilities; 3795 u8 *caps;
3796 u8 speed, max_speed;
3833 3797
3834 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE); 3798 idetape_create_mode_sense_cmd(&pc, IDETAPE_CAPABILITIES_PAGE);
3835 if (idetape_queue_pc_tail(drive, &pc)) { 3799 if (idetape_queue_pc_tail(drive, &pc)) {
3836 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming some default values\n"); 3800 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming"
3801 " some default values\n");
3837 tape->tape_block_size = 512; 3802 tape->tape_block_size = 512;
3838 tape->capabilities.ctl = 52; 3803 put_unaligned(52, (u16 *)&tape->caps[12]);
3839 tape->capabilities.speed = 450; 3804 put_unaligned(540, (u16 *)&tape->caps[14]);
3840 tape->capabilities.buffer_size = 6 * 52; 3805 put_unaligned(6*52, (u16 *)&tape->caps[16]);
3841 return; 3806 return;
3842 } 3807 }
3843 capabilities = (idetape_capabilities_page_t *) 3808 caps = pc.buffer + 4 + pc.buffer[3];
3844 (pc.buffer + 4 + pc.buffer[3]); 3809
3810 /* convert to host order and save for later use */
3811 speed = be16_to_cpu(*(u16 *)&caps[14]);
3812 max_speed = be16_to_cpu(*(u16 *)&caps[8]);
3845 3813
3846 capabilities->max_speed = ntohs(capabilities->max_speed); 3814 put_unaligned(max_speed, (u16 *)&caps[8]);
3847 capabilities->ctl = ntohs(capabilities->ctl); 3815 put_unaligned(be16_to_cpu(*(u16 *)&caps[12]), (u16 *)&caps[12]);
3848 capabilities->speed = ntohs(capabilities->speed); 3816 put_unaligned(speed, (u16 *)&caps[14]);
3849 capabilities->buffer_size = ntohs(capabilities->buffer_size); 3817 put_unaligned(be16_to_cpu(*(u16 *)&caps[16]), (u16 *)&caps[16]);
3850 3818
3851 if (!capabilities->speed) { 3819 if (!speed) {
3852 printk(KERN_INFO "ide-tape: %s: overriding capabilities->speed (assuming 650KB/sec)\n", drive->name); 3820 printk(KERN_INFO "ide-tape: %s: invalid tape speed "
3853 capabilities->speed = 650; 3821 "(assuming 650KB/sec)\n", drive->name);
3822 put_unaligned(650, (u16 *)&caps[14]);
3854 } 3823 }
3855 if (!capabilities->max_speed) { 3824 if (!max_speed) {
3856 printk(KERN_INFO "ide-tape: %s: overriding capabilities->max_speed (assuming 650KB/sec)\n", drive->name); 3825 printk(KERN_INFO "ide-tape: %s: invalid max_speed "
3857 capabilities->max_speed = 650; 3826 "(assuming 650KB/sec)\n", drive->name);
3827 put_unaligned(650, (u16 *)&caps[8]);
3858 } 3828 }
3859 3829
3860 tape->capabilities = *capabilities; /* Save us a copy */ 3830 memcpy(&tape->caps, caps, 20);
3861 if (capabilities->blk512) 3831 if (caps[7] & 0x02)
3862 tape->tape_block_size = 512; 3832 tape->tape_block_size = 512;
3863 else if (capabilities->blk1024) 3833 else if (caps[7] & 0x04)
3864 tape->tape_block_size = 1024; 3834 tape->tape_block_size = 1024;
3865} 3835}
3866 3836
@@ -3897,13 +3867,15 @@ static void idetape_add_settings (ide_drive_t *drive)
3897/* 3867/*
3898 * drive setting name read/write data type min max mul_factor div_factor data pointer set function 3868 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
3899 */ 3869 */
3900 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 2, &tape->capabilities.buffer_size, NULL); 3870 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff,
3871 1, 2, (u16 *)&tape->caps[16], NULL);
3901 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); 3872 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
3902 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL); 3873 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL);
3903 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); 3874 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
3904 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL); 3875 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL);
3905 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL); 3876 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL);
3906 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 1, &tape->capabilities.speed, NULL); 3877 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff,
3878 1, 1, (u16 *)&tape->caps[14], NULL);
3907 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL); 3879 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL);
3908 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL); 3880 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL);
3909 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); 3881 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL);
@@ -3935,6 +3907,7 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3935 struct idetape_id_gcw gcw; 3907 struct idetape_id_gcw gcw;
3936 int stage_size; 3908 int stage_size;
3937 struct sysinfo si; 3909 struct sysinfo si;
3910 u16 *ctl = (u16 *)&tape->caps[12];
3938 3911
3939 spin_lock_init(&tape->spinlock); 3912 spin_lock_init(&tape->spinlock);
3940 drive->dsc_overlap = 1; 3913 drive->dsc_overlap = 1;
@@ -3964,11 +3937,11 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3964 idetape_get_mode_sense_results(drive); 3937 idetape_get_mode_sense_results(drive);
3965 idetape_get_blocksize_from_block_descriptor(drive); 3938 idetape_get_blocksize_from_block_descriptor(drive);
3966 tape->user_bs_factor = 1; 3939 tape->user_bs_factor = 1;
3967 tape->stage_size = tape->capabilities.ctl * tape->tape_block_size; 3940 tape->stage_size = *ctl * tape->tape_block_size;
3968 while (tape->stage_size > 0xffff) { 3941 while (tape->stage_size > 0xffff) {
3969 printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); 3942 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
3970 tape->capabilities.ctl /= 2; 3943 *ctl /= 2;
3971 tape->stage_size = tape->capabilities.ctl * tape->tape_block_size; 3944 tape->stage_size = *ctl * tape->tape_block_size;
3972 } 3945 }
3973 stage_size = tape->stage_size; 3946 stage_size = tape->stage_size;
3974 tape->pages_per_stage = stage_size / PAGE_SIZE; 3947 tape->pages_per_stage = stage_size / PAGE_SIZE;
@@ -3977,11 +3950,8 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3977 tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE; 3950 tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE;
3978 } 3951 }
3979 3952
3980 /* 3953 /* Select the "best" DSC read/write polling freq and pipeline size. */
3981 * Select the "best" DSC read/write polling frequency 3954 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
3982 * and pipeline size.
3983 */
3984 speed = max(tape->capabilities.speed, tape->capabilities.max_speed);
3985 3955
3986 tape->max_stages = speed * 1000 * 10 / tape->stage_size; 3956 tape->max_stages = speed * 1000 * 10 / tape->stage_size;
3987 3957
@@ -3998,7 +3968,7 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
3998 tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1; 3968 tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1;
3999 3969
4000 t1 = (tape->stage_size * HZ) / (speed * 1000); 3970 t1 = (tape->stage_size * HZ) / (speed * 1000);
4001 tmid = (tape->capabilities.buffer_size * 32 * HZ) / (speed * 125); 3971 tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125);
4002 tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000); 3972 tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000);
4003 3973
4004 if (tape->max_stages) 3974 if (tape->max_stages)
@@ -4013,8 +3983,8 @@ static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
4013 tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN); 3983 tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN);
4014 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " 3984 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
4015 "%dkB pipeline, %lums tDSC%s\n", 3985 "%dkB pipeline, %lums tDSC%s\n",
4016 drive->name, tape->name, tape->capabilities.speed, 3986 drive->name, tape->name, *(u16 *)&tape->caps[14],
4017 (tape->capabilities.buffer_size * 512) / tape->stage_size, 3987 (*(u16 *)&tape->caps[16] * 512) / tape->stage_size,
4018 tape->stage_size / 1024, 3988 tape->stage_size / 1024,
4019 tape->max_stages * tape->stage_size / 1024, 3989 tape->max_stages * tape->stage_size / 1024,
4020 tape->best_dsc_rw_frequency * 1000 / HZ, 3990 tape->best_dsc_rw_frequency * 1000 / HZ,