aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
authorBorislav Petkov <petkovbb@googlemail.com>2008-04-27 09:38:27 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-27 09:38:27 -0400
commit83042b241601170c95b448267861be10a6025b3c (patch)
treed4a46faf598f9eaf3b8f6ee4ad5d97e95489ee1f /drivers/ide/ide-tape.c
parent42d5468921e9e9c0a2d13048a2dab09f844e18bc (diff)
ide-tape: remove pipeline-specific members from struct ide_tape_obj
Bart: - merge "ide-tape: remove pipeline-specific code from idetape_setup" patch - cleanup __idetape_discard_read_pipeline() - cleanup idetape_empty_write_pipeline() - fix 't' assignment in idetape_setup() - fix idetape_blkdev_ioctl() w.r.t. 'nr_stages' Signed-off-by: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c170
1 files changed, 14 insertions, 156 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index c4b470999203..a81644b2473e 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -324,12 +324,8 @@ typedef struct ide_tape_obj {
324 * At most, there is only one ide-tape originated data transfer request 324 * At most, there is only one ide-tape originated data transfer request
325 * in the device request queue. This allows ide.c to easily service 325 * in the device request queue. This allows ide.c to easily service
326 * requests from the other device when we postpone our active request. 326 * requests from the other device when we postpone our active request.
327 * In the pipelined operation mode, we use our internal pipeline
328 * structure to hold more data requests. The data buffer size is chosen
329 * based on the tape's recommendation.
330 */ 327 */
331 /* ptr to the request which is waiting in the device request queue */ 328
332 struct request *active_data_rq;
333 /* Data buffer size chosen based on the tape's recommendation */ 329 /* Data buffer size chosen based on the tape's recommendation */
334 int stage_size; 330 int stage_size;
335 idetape_stage_t *merge_stage; 331 idetape_stage_t *merge_stage;
@@ -338,26 +334,7 @@ typedef struct ide_tape_obj {
338 char *b_data; 334 char *b_data;
339 int b_count; 335 int b_count;
340 336
341 /* 337 /* Pipeline parameters. */
342 * Pipeline parameters.
343 *
344 * To accomplish non-pipelined mode, we simply set the following
345 * variables to zero (or NULL, where appropriate).
346 */
347 /* Number of currently used stages */
348 int nr_stages;
349 /* Number of pending stages */
350 int nr_pending_stages;
351 /* We will not allocate more than this number of stages */
352 int max_stages, min_pipeline, max_pipeline;
353 /* The first stage which will be removed from the pipeline */
354 idetape_stage_t *first_stage;
355 /* The currently active stage */
356 idetape_stage_t *active_stage;
357 /* Will be serviced after the currently active request */
358 idetape_stage_t *next_stage;
359 /* New requests will be added to the pipeline here */
360 idetape_stage_t *last_stage;
361 int pages_per_stage; 338 int pages_per_stage;
362 /* Wasted space in each stage */ 339 /* Wasted space in each stage */
363 int excess_bh_size; 340 int excess_bh_size;
@@ -379,18 +356,6 @@ typedef struct ide_tape_obj {
379 /* the tape is write protected (hardware or opened as read-only) */ 356 /* the tape is write protected (hardware or opened as read-only) */
380 char write_prot; 357 char write_prot;
381 358
382 /*
383 * Limit the number of times a request can be postponed, to avoid an
384 * infinite postpone deadlock.
385 */
386 int postpone_cnt;
387
388 /* Speed control at the tape buffers input/output */
389 unsigned long insert_time;
390 int insert_size;
391 int insert_speed;
392 int measure_insert_time;
393
394 u32 debug_mask; 359 u32 debug_mask;
395} idetape_tape_t; 360} idetape_tape_t;
396 361
@@ -1193,17 +1158,7 @@ static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
1193 int blocks = tape->pc->xferred / tape->blk_size; 1158 int blocks = tape->pc->xferred / tape->blk_size;
1194 1159
1195 tape->avg_size += blocks * tape->blk_size; 1160 tape->avg_size += blocks * tape->blk_size;
1196 tape->insert_size += blocks * tape->blk_size; 1161
1197 if (tape->insert_size > 1024 * 1024)
1198 tape->measure_insert_time = 1;
1199 if (tape->measure_insert_time) {
1200 tape->measure_insert_time = 0;
1201 tape->insert_time = jiffies;
1202 tape->insert_size = 0;
1203 }
1204 if (time_after(jiffies, tape->insert_time))
1205 tape->insert_speed = tape->insert_size / 1024 * HZ /
1206 (jiffies - tape->insert_time);
1207 if (time_after_eq(jiffies, tape->avg_time + HZ)) { 1162 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
1208 tape->avg_speed = tape->avg_size * HZ / 1163 tape->avg_speed = tape->avg_size * HZ /
1209 (jiffies - tape->avg_time) / 1024; 1164 (jiffies - tape->avg_time) / 1024;
@@ -1308,9 +1263,6 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1308 drive->post_reset = 0; 1263 drive->post_reset = 0;
1309 } 1264 }
1310 1265
1311 if (time_after(jiffies, tape->insert_time))
1312 tape->insert_speed = tape->insert_size / 1024 * HZ /
1313 (jiffies - tape->insert_time);
1314 if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) && 1266 if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) &&
1315 (stat & SEEK_STAT) == 0) { 1267 (stat & SEEK_STAT) == 0) {
1316 if (postponed_rq == NULL) { 1268 if (postponed_rq == NULL) {
@@ -1334,14 +1286,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
1334 return ide_stopped; 1286 return ide_stopped;
1335 } 1287 }
1336 if (rq->cmd[0] & REQ_IDETAPE_READ) { 1288 if (rq->cmd[0] & REQ_IDETAPE_READ) {
1337 tape->postpone_cnt = 0;
1338 pc = idetape_next_pc_storage(drive); 1289 pc = idetape_next_pc_storage(drive);
1339 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, 1290 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors,
1340 (struct idetape_bh *)rq->special); 1291 (struct idetape_bh *)rq->special);
1341 goto out; 1292 goto out;
1342 } 1293 }
1343 if (rq->cmd[0] & REQ_IDETAPE_WRITE) { 1294 if (rq->cmd[0] & REQ_IDETAPE_WRITE) {
1344 tape->postpone_cnt = 0;
1345 pc = idetape_next_pc_storage(drive); 1295 pc = idetape_next_pc_storage(drive);
1346 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, 1296 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors,
1347 (struct idetape_bh *)rq->special); 1297 (struct idetape_bh *)rq->special);
@@ -1707,16 +1657,11 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
1707static int __idetape_discard_read_pipeline(ide_drive_t *drive) 1657static int __idetape_discard_read_pipeline(ide_drive_t *drive)
1708{ 1658{
1709 idetape_tape_t *tape = drive->driver_data; 1659 idetape_tape_t *tape = drive->driver_data;
1710 unsigned long flags;
1711 int cnt;
1712 1660
1713 if (tape->chrdev_dir != IDETAPE_DIR_READ) 1661 if (tape->chrdev_dir != IDETAPE_DIR_READ)
1714 return 0; 1662 return 0;
1715 1663
1716 /* Remove merge stage. */ 1664 clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags);
1717 cnt = tape->merge_stage_size / tape->blk_size;
1718 if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags))
1719 ++cnt; /* Filemarks count as 1 sector */
1720 tape->merge_stage_size = 0; 1665 tape->merge_stage_size = 0;
1721 if (tape->merge_stage != NULL) { 1666 if (tape->merge_stage != NULL) {
1722 __idetape_kfree_stage(tape->merge_stage); 1667 __idetape_kfree_stage(tape->merge_stage);
@@ -1725,24 +1670,7 @@ static int __idetape_discard_read_pipeline(ide_drive_t *drive)
1725 1670
1726 tape->chrdev_dir = IDETAPE_DIR_NONE; 1671 tape->chrdev_dir = IDETAPE_DIR_NONE;
1727 1672
1728 /* Remove pipeline stages. */ 1673 return 0;
1729 if (tape->first_stage == NULL)
1730 return 0;
1731
1732 spin_lock_irqsave(&tape->lock, flags);
1733 tape->next_stage = NULL;
1734 spin_unlock_irqrestore(&tape->lock, flags);
1735
1736 while (tape->first_stage != NULL) {
1737 struct request *rq_ptr = &tape->first_stage->rq;
1738
1739 cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors;
1740 if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK)
1741 ++cnt;
1742 }
1743 tape->nr_pending_stages = 0;
1744 tape->max_stages = tape->min_pipeline;
1745 return cnt;
1746} 1674}
1747 1675
1748/* 1676/*
@@ -1919,27 +1847,9 @@ static void idetape_empty_write_pipeline(ide_drive_t *drive)
1919 tape->merge_stage = NULL; 1847 tape->merge_stage = NULL;
1920 } 1848 }
1921 tape->chrdev_dir = IDETAPE_DIR_NONE; 1849 tape->chrdev_dir = IDETAPE_DIR_NONE;
1922
1923 /*
1924 * On the next backup, perform the feedback loop again. (I don't want to
1925 * keep sense information between backups, as some systems are
1926 * constantly on, and the system load can be totally different on the
1927 * next backup).
1928 */
1929 tape->max_stages = tape->min_pipeline;
1930 if (tape->first_stage != NULL ||
1931 tape->next_stage != NULL ||
1932 tape->last_stage != NULL ||
1933 tape->nr_stages != 0) {
1934 printk(KERN_ERR "ide-tape: ide-tape pipeline bug, "
1935 "first_stage %p, next_stage %p, "
1936 "last_stage %p, nr_stages %d\n",
1937 tape->first_stage, tape->next_stage,
1938 tape->last_stage, tape->nr_stages);
1939 }
1940} 1850}
1941 1851
1942static int idetape_init_read(ide_drive_t *drive, int max_stages) 1852static int idetape_init_read(ide_drive_t *drive)
1943{ 1853{
1944 idetape_tape_t *tape = drive->driver_data; 1854 idetape_tape_t *tape = drive->driver_data;
1945 int bytes_read; 1855 int bytes_read;
@@ -1979,13 +1889,6 @@ static int idetape_init_read(ide_drive_t *drive, int max_stages)
1979 } 1889 }
1980 } 1890 }
1981 1891
1982 if (tape->nr_pending_stages >= 3 * max_stages / 4) {
1983 tape->measure_insert_time = 1;
1984 tape->insert_time = jiffies;
1985 tape->insert_size = 0;
1986 tape->insert_speed = 0;
1987 }
1988
1989 return 0; 1892 return 0;
1990} 1893}
1991 1894
@@ -2003,7 +1906,7 @@ static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks)
2003 if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) 1906 if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags))
2004 return 0; 1907 return 0;
2005 1908
2006 idetape_init_read(drive, tape->max_stages); 1909 idetape_init_read(drive);
2007 1910
2008 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, 1911 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks,
2009 tape->merge_stage->bh); 1912 tape->merge_stage->bh);
@@ -2079,11 +1982,10 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd,
2079 if (copy_from_user(&config, argp, sizeof(config))) 1982 if (copy_from_user(&config, argp, sizeof(config)))
2080 return -EFAULT; 1983 return -EFAULT;
2081 tape->best_dsc_rw_freq = config.dsc_rw_frequency; 1984 tape->best_dsc_rw_freq = config.dsc_rw_frequency;
2082 tape->max_stages = config.nr_stages;
2083 break; 1985 break;
2084 case 0x0350: 1986 case 0x0350:
2085 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; 1987 config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq;
2086 config.nr_stages = tape->max_stages; 1988 config.nr_stages = 1;
2087 if (copy_to_user(argp, &config, sizeof(config))) 1989 if (copy_to_user(argp, &config, sizeof(config)))
2088 return -EFAULT; 1990 return -EFAULT;
2089 break; 1991 break;
@@ -2175,7 +2077,7 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
2175 (count % tape->blk_size) == 0) 2077 (count % tape->blk_size) == 0)
2176 tape->user_bs_factor = count / tape->blk_size; 2078 tape->user_bs_factor = count / tape->blk_size;
2177 } 2079 }
2178 rc = idetape_init_read(drive, tape->max_stages); 2080 rc = idetape_init_read(drive);
2179 if (rc < 0) 2081 if (rc < 0)
2180 return rc; 2082 return rc;
2181 if (count == 0) 2083 if (count == 0)
@@ -2793,18 +2695,6 @@ static void idetape_add_settings(ide_drive_t *drive)
2793 2695
2794 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2696 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff,
2795 1, 2, (u16 *)&tape->caps[16], NULL); 2697 1, 2, (u16 *)&tape->caps[16], NULL);
2796 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff,
2797 tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
2798 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff,
2799 tape->stage_size / 1024, 1, &tape->max_stages, NULL);
2800 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff,
2801 tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
2802 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0,
2803 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages,
2804 NULL);
2805 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0,
2806 0xffff, tape->stage_size / 1024, 1,
2807 &tape->nr_pending_stages, NULL);
2808 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 2698 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff,
2809 1, 1, (u16 *)&tape->caps[14], NULL); 2699 1, 1, (u16 *)&tape->caps[14], NULL);
2810 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 2700 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1,
@@ -2836,11 +2726,10 @@ static inline void idetape_add_settings(ide_drive_t *drive) { ; }
2836 */ 2726 */
2837static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) 2727static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2838{ 2728{
2839 unsigned long t1, tmid, tn, t; 2729 unsigned long t;
2840 int speed; 2730 int speed;
2841 int stage_size; 2731 int stage_size;
2842 u8 gcw[2]; 2732 u8 gcw[2];
2843 struct sysinfo si;
2844 u16 *ctl = (u16 *)&tape->caps[12]; 2733 u16 *ctl = (u16 *)&tape->caps[12];
2845 2734
2846 spin_lock_init(&tape->lock); 2735 spin_lock_init(&tape->lock);
@@ -2865,10 +2754,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2865 if (((gcw[0] & 0x60) >> 5) == 1) 2754 if (((gcw[0] & 0x60) >> 5) == 1)
2866 set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags); 2755 set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags);
2867 2756
2868 tape->min_pipeline = 10;
2869 tape->max_pipeline = 10;
2870 tape->max_stages = 10;
2871
2872 idetape_get_inquiry_results(drive); 2757 idetape_get_inquiry_results(drive);
2873 idetape_get_mode_sense_results(drive); 2758 idetape_get_mode_sense_results(drive);
2874 ide_tape_get_bsize_from_bdesc(drive); 2759 ide_tape_get_bsize_from_bdesc(drive);
@@ -2886,36 +2771,10 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2886 tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE; 2771 tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE;
2887 } 2772 }
2888 2773
2889 /* Select the "best" DSC read/write polling freq and pipeline size. */ 2774 /* select the "best" DSC read/write polling freq */
2890 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); 2775 speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]);
2891 2776
2892 tape->max_stages = speed * 1000 * 10 / tape->stage_size; 2777 t = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000);
2893
2894 /* Limit memory use for pipeline to 10% of physical memory */
2895 si_meminfo(&si);
2896 if (tape->max_stages * tape->stage_size >
2897 si.totalram * si.mem_unit / 10)
2898 tape->max_stages =
2899 si.totalram * si.mem_unit / (10 * tape->stage_size);
2900
2901 tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES);
2902 tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES);
2903 tape->max_pipeline =
2904 min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES);
2905 if (tape->max_stages == 0) {
2906 tape->max_stages = 1;
2907 tape->min_pipeline = 1;
2908 tape->max_pipeline = 1;
2909 }
2910
2911 t1 = (tape->stage_size * HZ) / (speed * 1000);
2912 tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125);
2913 tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000);
2914
2915 if (tape->max_stages)
2916 t = tn;
2917 else
2918 t = t1;
2919 2778
2920 /* 2779 /*
2921 * Ensure that the number we got makes sense; limit it within 2780 * Ensure that the number we got makes sense; limit it within
@@ -2925,11 +2784,10 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2925 min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), 2784 min_t(unsigned long, t, IDETAPE_DSC_RW_MAX),
2926 IDETAPE_DSC_RW_MIN); 2785 IDETAPE_DSC_RW_MIN);
2927 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " 2786 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
2928 "%dkB pipeline, %lums tDSC%s\n", 2787 "%lums tDSC%s\n",
2929 drive->name, tape->name, *(u16 *)&tape->caps[14], 2788 drive->name, tape->name, *(u16 *)&tape->caps[14],
2930 (*(u16 *)&tape->caps[16] * 512) / tape->stage_size, 2789 (*(u16 *)&tape->caps[16] * 512) / tape->stage_size,
2931 tape->stage_size / 1024, 2790 tape->stage_size / 1024,
2932 tape->max_stages * tape->stage_size / 1024,
2933 tape->best_dsc_rw_freq * 1000 / HZ, 2791 tape->best_dsc_rw_freq * 1000 / HZ,
2934 drive->using_dma ? ", DMA":""); 2792 drive->using_dma ? ", DMA":"");
2935 2793
@@ -2953,7 +2811,7 @@ static void ide_tape_release(struct kref *kref)
2953 ide_drive_t *drive = tape->drive; 2811 ide_drive_t *drive = tape->drive;
2954 struct gendisk *g = tape->disk; 2812 struct gendisk *g = tape->disk;
2955 2813
2956 BUG_ON(tape->first_stage != NULL || tape->merge_stage_size); 2814 BUG_ON(tape->merge_stage_size);
2957 2815
2958 drive->dsc_overlap = 0; 2816 drive->dsc_overlap = 0;
2959 drive->driver_data = NULL; 2817 drive->driver_data = NULL;