diff options
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r-- | drivers/ide/ide-tape.c | 1191 |
1 files changed, 207 insertions, 984 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index d3d8b8d5157c..29870c415110 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -72,26 +72,6 @@ enum { | |||
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | /**************************** Tunable parameters *****************************/ | 74 | /**************************** Tunable parameters *****************************/ |
75 | |||
76 | |||
77 | /* | ||
78 | * Pipelined mode parameters. | ||
79 | * | ||
80 | * We try to use the minimum number of stages which is enough to keep the tape | ||
81 | * constantly streaming. To accomplish that, we implement a feedback loop around | ||
82 | * the maximum number of stages: | ||
83 | * | ||
84 | * We start from MIN maximum stages (we will not even use MIN stages if we don't | ||
85 | * need them), increment it by RATE*(MAX-MIN) whenever we sense that the | ||
86 | * pipeline is empty, until we reach the optimum value or until we reach MAX. | ||
87 | * | ||
88 | * Setting the following parameter to 0 is illegal: the pipelined mode cannot be | ||
89 | * disabled (idetape_calculate_speeds() divides by tape->max_stages.) | ||
90 | */ | ||
91 | #define IDETAPE_MIN_PIPELINE_STAGES 1 | ||
92 | #define IDETAPE_MAX_PIPELINE_STAGES 400 | ||
93 | #define IDETAPE_INCREASE_STAGES_RATE 20 | ||
94 | |||
95 | /* | 75 | /* |
96 | * After each failed packet command we issue a request sense command and retry | 76 | * After each failed packet command we issue a request sense command and retry |
97 | * the packet command IDETAPE_MAX_PC_RETRIES times. | 77 | * the packet command IDETAPE_MAX_PC_RETRIES times. |
@@ -224,28 +204,17 @@ enum { | |||
224 | /* 0 When the tape position is unknown */ | 204 | /* 0 When the tape position is unknown */ |
225 | IDETAPE_FLAG_ADDRESS_VALID = (1 << 1), | 205 | IDETAPE_FLAG_ADDRESS_VALID = (1 << 1), |
226 | /* Device already opened */ | 206 | /* Device already opened */ |
227 | IDETAPE_FLAG_BUSY = (1 << 2), | 207 | IDETAPE_FLAG_BUSY = (1 << 2), |
228 | /* Error detected in a pipeline stage */ | ||
229 | IDETAPE_FLAG_PIPELINE_ERR = (1 << 3), | ||
230 | /* Attempt to auto-detect the current user block size */ | 208 | /* Attempt to auto-detect the current user block size */ |
231 | IDETAPE_FLAG_DETECT_BS = (1 << 4), | 209 | IDETAPE_FLAG_DETECT_BS = (1 << 3), |
232 | /* Currently on a filemark */ | 210 | /* Currently on a filemark */ |
233 | IDETAPE_FLAG_FILEMARK = (1 << 5), | 211 | IDETAPE_FLAG_FILEMARK = (1 << 4), |
234 | /* DRQ interrupt device */ | 212 | /* DRQ interrupt device */ |
235 | IDETAPE_FLAG_DRQ_INTERRUPT = (1 << 6), | 213 | IDETAPE_FLAG_DRQ_INTERRUPT = (1 << 5), |
236 | /* pipeline active */ | ||
237 | IDETAPE_FLAG_PIPELINE_ACTIVE = (1 << 7), | ||
238 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ | 214 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ |
239 | IDETAPE_FLAG_MEDIUM_PRESENT = (1 << 8), | 215 | IDETAPE_FLAG_MEDIUM_PRESENT = (1 << 6), |
240 | }; | 216 | }; |
241 | 217 | ||
242 | /* A pipeline stage. */ | ||
243 | typedef struct idetape_stage_s { | ||
244 | struct request rq; /* The corresponding request */ | ||
245 | struct idetape_bh *bh; /* The data buffers */ | ||
246 | struct idetape_stage_s *next; /* Pointer to the next stage */ | ||
247 | } idetape_stage_t; | ||
248 | |||
249 | /* | 218 | /* |
250 | * Most of our global data which we need to save even as we leave the driver due | 219 | * Most of our global data which we need to save even as we leave the driver due |
251 | * to an interrupt or a timer event is stored in the struct defined below. | 220 | * to an interrupt or a timer event is stored in the struct defined below. |
@@ -289,9 +258,7 @@ typedef struct ide_tape_obj { | |||
289 | * While polling for DSC we use postponed_rq to postpone the current | 258 | * While polling for DSC we use postponed_rq to postpone the current |
290 | * request so that ide.c will be able to service pending requests on the | 259 | * request so that ide.c will be able to service pending requests on the |
291 | * other device. Note that at most we will have only one DSC (usually | 260 | * other device. Note that at most we will have only one DSC (usually |
292 | * data transfer) request in the device request queue. Additional | 261 | * data transfer) request in the device request queue. |
293 | * requests can be queued in our internal pipeline, but they will be | ||
294 | * visible to ide.c only one at a time. | ||
295 | */ | 262 | */ |
296 | struct request *postponed_rq; | 263 | struct request *postponed_rq; |
297 | /* The time in which we started polling for DSC */ | 264 | /* The time in which we started polling for DSC */ |
@@ -331,43 +298,20 @@ typedef struct ide_tape_obj { | |||
331 | * At most, there is only one ide-tape originated data transfer request | 298 | * At most, there is only one ide-tape originated data transfer request |
332 | * in the device request queue. This allows ide.c to easily service | 299 | * in the device request queue. This allows ide.c to easily service |
333 | * requests from the other device when we postpone our active request. | 300 | * requests from the other device when we postpone our active request. |
334 | * In the pipelined operation mode, we use our internal pipeline | ||
335 | * structure to hold more data requests. The data buffer size is chosen | ||
336 | * based on the tape's recommendation. | ||
337 | */ | 301 | */ |
338 | /* ptr to the request which is waiting in the device request queue */ | 302 | |
339 | struct request *active_data_rq; | ||
340 | /* Data buffer size chosen based on the tape's recommendation */ | 303 | /* Data buffer size chosen based on the tape's recommendation */ |
341 | int stage_size; | 304 | int buffer_size; |
342 | idetape_stage_t *merge_stage; | 305 | /* merge buffer */ |
343 | int merge_stage_size; | 306 | struct idetape_bh *merge_bh; |
307 | /* size of the merge buffer */ | ||
308 | int merge_bh_size; | ||
309 | /* pointer to current buffer head within the merge buffer */ | ||
344 | struct idetape_bh *bh; | 310 | struct idetape_bh *bh; |
345 | char *b_data; | 311 | char *b_data; |
346 | int b_count; | 312 | int b_count; |
347 | 313 | ||
348 | /* | 314 | int pages_per_buffer; |
349 | * Pipeline parameters. | ||
350 | * | ||
351 | * To accomplish non-pipelined mode, we simply set the following | ||
352 | * variables to zero (or NULL, where appropriate). | ||
353 | */ | ||
354 | /* Number of currently used stages */ | ||
355 | int nr_stages; | ||
356 | /* Number of pending stages */ | ||
357 | int nr_pending_stages; | ||
358 | /* We will not allocate more than this number of stages */ | ||
359 | int max_stages, min_pipeline, max_pipeline; | ||
360 | /* The first stage which will be removed from the pipeline */ | ||
361 | idetape_stage_t *first_stage; | ||
362 | /* The currently active stage */ | ||
363 | idetape_stage_t *active_stage; | ||
364 | /* Will be serviced after the currently active request */ | ||
365 | idetape_stage_t *next_stage; | ||
366 | /* New requests will be added to the pipeline here */ | ||
367 | idetape_stage_t *last_stage; | ||
368 | /* Optional free stage which we can use */ | ||
369 | idetape_stage_t *cache_stage; | ||
370 | int pages_per_stage; | ||
371 | /* Wasted space in each stage */ | 315 | /* Wasted space in each stage */ |
372 | int excess_bh_size; | 316 | int excess_bh_size; |
373 | 317 | ||
@@ -388,45 +332,6 @@ typedef struct ide_tape_obj { | |||
388 | /* the tape is write protected (hardware or opened as read-only) */ | 332 | /* the tape is write protected (hardware or opened as read-only) */ |
389 | char write_prot; | 333 | char write_prot; |
390 | 334 | ||
391 | /* | ||
392 | * Limit the number of times a request can be postponed, to avoid an | ||
393 | * infinite postpone deadlock. | ||
394 | */ | ||
395 | int postpone_cnt; | ||
396 | |||
397 | /* | ||
398 | * Measures number of frames: | ||
399 | * | ||
400 | * 1. written/read to/from the driver pipeline (pipeline_head). | ||
401 | * 2. written/read to/from the tape buffers (idetape_bh). | ||
402 | * 3. written/read by the tape to/from the media (tape_head). | ||
403 | */ | ||
404 | int pipeline_head; | ||
405 | int buffer_head; | ||
406 | int tape_head; | ||
407 | int last_tape_head; | ||
408 | |||
409 | /* Speed control at the tape buffers input/output */ | ||
410 | unsigned long insert_time; | ||
411 | int insert_size; | ||
412 | int insert_speed; | ||
413 | int max_insert_speed; | ||
414 | int measure_insert_time; | ||
415 | |||
416 | /* Speed regulation negative feedback loop */ | ||
417 | int speed_control; | ||
418 | int pipeline_head_speed; | ||
419 | int controlled_pipeline_head_speed; | ||
420 | int uncontrolled_pipeline_head_speed; | ||
421 | int controlled_last_pipeline_head; | ||
422 | unsigned long uncontrolled_pipeline_head_time; | ||
423 | unsigned long controlled_pipeline_head_time; | ||
424 | int controlled_previous_pipeline_head; | ||
425 | int uncontrolled_previous_pipeline_head; | ||
426 | unsigned long controlled_previous_head_time; | ||
427 | unsigned long uncontrolled_previous_head_time; | ||
428 | int restart_speed_control_req; | ||
429 | |||
430 | u32 debug_mask; | 335 | u32 debug_mask; |
431 | } idetape_tape_t; | 336 | } idetape_tape_t; |
432 | 337 | ||
@@ -674,128 +579,36 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense) | |||
674 | } | 579 | } |
675 | } | 580 | } |
676 | 581 | ||
677 | static void idetape_activate_next_stage(ide_drive_t *drive) | 582 | /* Free data buffers completely. */ |
583 | static void ide_tape_kfree_buffer(idetape_tape_t *tape) | ||
678 | { | 584 | { |
679 | idetape_tape_t *tape = drive->driver_data; | 585 | struct idetape_bh *prev_bh, *bh = tape->merge_bh; |
680 | idetape_stage_t *stage = tape->next_stage; | ||
681 | struct request *rq = &stage->rq; | ||
682 | 586 | ||
683 | debug_log(DBG_PROCS, "Enter %s\n", __func__); | 587 | while (bh) { |
588 | u32 size = bh->b_size; | ||
684 | 589 | ||
685 | if (stage == NULL) { | 590 | while (size) { |
686 | printk(KERN_ERR "ide-tape: bug: Trying to activate a non" | 591 | unsigned int order = fls(size >> PAGE_SHIFT)-1; |
687 | " existing stage\n"); | ||
688 | return; | ||
689 | } | ||
690 | 592 | ||
691 | rq->rq_disk = tape->disk; | 593 | if (bh->b_data) |
692 | rq->buffer = NULL; | 594 | free_pages((unsigned long)bh->b_data, order); |
693 | rq->special = (void *)stage->bh; | 595 | |
694 | tape->active_data_rq = rq; | 596 | size &= (order-1); |
695 | tape->active_stage = stage; | 597 | bh->b_data += (1 << order) * PAGE_SIZE; |
696 | tape->next_stage = stage->next; | ||
697 | } | ||
698 | |||
699 | /* Free a stage along with its related buffers completely. */ | ||
700 | static void __idetape_kfree_stage(idetape_stage_t *stage) | ||
701 | { | ||
702 | struct idetape_bh *prev_bh, *bh = stage->bh; | ||
703 | int size; | ||
704 | |||
705 | while (bh != NULL) { | ||
706 | if (bh->b_data != NULL) { | ||
707 | size = (int) bh->b_size; | ||
708 | while (size > 0) { | ||
709 | free_page((unsigned long) bh->b_data); | ||
710 | size -= PAGE_SIZE; | ||
711 | bh->b_data += PAGE_SIZE; | ||
712 | } | ||
713 | } | 598 | } |
714 | prev_bh = bh; | 599 | prev_bh = bh; |
715 | bh = bh->b_reqnext; | 600 | bh = bh->b_reqnext; |
716 | kfree(prev_bh); | 601 | kfree(prev_bh); |
717 | } | 602 | } |
718 | kfree(stage); | 603 | kfree(tape->merge_bh); |
719 | } | ||
720 | |||
721 | static void idetape_kfree_stage(idetape_tape_t *tape, idetape_stage_t *stage) | ||
722 | { | ||
723 | __idetape_kfree_stage(stage); | ||
724 | } | ||
725 | |||
726 | /* | ||
727 | * Remove tape->first_stage from the pipeline. The caller should avoid race | ||
728 | * conditions. | ||
729 | */ | ||
730 | static void idetape_remove_stage_head(ide_drive_t *drive) | ||
731 | { | ||
732 | idetape_tape_t *tape = drive->driver_data; | ||
733 | idetape_stage_t *stage; | ||
734 | |||
735 | debug_log(DBG_PROCS, "Enter %s\n", __func__); | ||
736 | |||
737 | if (tape->first_stage == NULL) { | ||
738 | printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n"); | ||
739 | return; | ||
740 | } | ||
741 | if (tape->active_stage == tape->first_stage) { | ||
742 | printk(KERN_ERR "ide-tape: bug: Trying to free our active " | ||
743 | "pipeline stage\n"); | ||
744 | return; | ||
745 | } | ||
746 | stage = tape->first_stage; | ||
747 | tape->first_stage = stage->next; | ||
748 | idetape_kfree_stage(tape, stage); | ||
749 | tape->nr_stages--; | ||
750 | if (tape->first_stage == NULL) { | ||
751 | tape->last_stage = NULL; | ||
752 | if (tape->next_stage != NULL) | ||
753 | printk(KERN_ERR "ide-tape: bug: tape->next_stage !=" | ||
754 | " NULL\n"); | ||
755 | if (tape->nr_stages) | ||
756 | printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 " | ||
757 | "now\n"); | ||
758 | } | ||
759 | } | 604 | } |
760 | 605 | ||
761 | /* | ||
762 | * This will free all the pipeline stages starting from new_last_stage->next | ||
763 | * to the end of the list, and point tape->last_stage to new_last_stage. | ||
764 | */ | ||
765 | static void idetape_abort_pipeline(ide_drive_t *drive, | ||
766 | idetape_stage_t *new_last_stage) | ||
767 | { | ||
768 | idetape_tape_t *tape = drive->driver_data; | ||
769 | idetape_stage_t *stage = new_last_stage->next; | ||
770 | idetape_stage_t *nstage; | ||
771 | |||
772 | debug_log(DBG_PROCS, "%s: Enter %s\n", tape->name, __func__); | ||
773 | |||
774 | while (stage) { | ||
775 | nstage = stage->next; | ||
776 | idetape_kfree_stage(tape, stage); | ||
777 | --tape->nr_stages; | ||
778 | --tape->nr_pending_stages; | ||
779 | stage = nstage; | ||
780 | } | ||
781 | if (new_last_stage) | ||
782 | new_last_stage->next = NULL; | ||
783 | tape->last_stage = new_last_stage; | ||
784 | tape->next_stage = NULL; | ||
785 | } | ||
786 | |||
787 | /* | ||
788 | * Finish servicing a request and insert a pending pipeline request into the | ||
789 | * main device queue. | ||
790 | */ | ||
791 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) | 606 | static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) |
792 | { | 607 | { |
793 | struct request *rq = HWGROUP(drive)->rq; | 608 | struct request *rq = HWGROUP(drive)->rq; |
794 | idetape_tape_t *tape = drive->driver_data; | 609 | idetape_tape_t *tape = drive->driver_data; |
795 | unsigned long flags; | 610 | unsigned long flags; |
796 | int error; | 611 | int error; |
797 | int remove_stage = 0; | ||
798 | idetape_stage_t *active_stage; | ||
799 | 612 | ||
800 | debug_log(DBG_PROCS, "Enter %s\n", __func__); | 613 | debug_log(DBG_PROCS, "Enter %s\n", __func__); |
801 | 614 | ||
@@ -815,58 +628,8 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects) | |||
815 | 628 | ||
816 | spin_lock_irqsave(&tape->lock, flags); | 629 | spin_lock_irqsave(&tape->lock, flags); |
817 | 630 | ||
818 | /* The request was a pipelined data transfer request */ | ||
819 | if (tape->active_data_rq == rq) { | ||
820 | active_stage = tape->active_stage; | ||
821 | tape->active_stage = NULL; | ||
822 | tape->active_data_rq = NULL; | ||
823 | tape->nr_pending_stages--; | ||
824 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { | ||
825 | remove_stage = 1; | ||
826 | if (error) { | ||
827 | set_bit(IDETAPE_FLAG_PIPELINE_ERR, | ||
828 | &tape->flags); | ||
829 | if (error == IDETAPE_ERROR_EOD) | ||
830 | idetape_abort_pipeline(drive, | ||
831 | active_stage); | ||
832 | } | ||
833 | } else if (rq->cmd[0] & REQ_IDETAPE_READ) { | ||
834 | if (error == IDETAPE_ERROR_EOD) { | ||
835 | set_bit(IDETAPE_FLAG_PIPELINE_ERR, | ||
836 | &tape->flags); | ||
837 | idetape_abort_pipeline(drive, active_stage); | ||
838 | } | ||
839 | } | ||
840 | if (tape->next_stage != NULL) { | ||
841 | idetape_activate_next_stage(drive); | ||
842 | |||
843 | /* Insert the next request into the request queue. */ | ||
844 | (void)ide_do_drive_cmd(drive, tape->active_data_rq, | ||
845 | ide_end); | ||
846 | } else if (!error) { | ||
847 | /* | ||
848 | * This is a part of the feedback loop which tries to | ||
849 | * find the optimum number of stages. We are starting | ||
850 | * from a minimum maximum number of stages, and if we | ||
851 | * sense that the pipeline is empty, we try to increase | ||
852 | * it, until we reach the user compile time memory | ||
853 | * limit. | ||
854 | */ | ||
855 | int i = (tape->max_pipeline - tape->min_pipeline) / 10; | ||
856 | |||
857 | tape->max_stages += max(i, 1); | ||
858 | tape->max_stages = max(tape->max_stages, | ||
859 | tape->min_pipeline); | ||
860 | tape->max_stages = min(tape->max_stages, | ||
861 | tape->max_pipeline); | ||
862 | } | ||
863 | } | ||
864 | ide_end_drive_cmd(drive, 0, 0); | 631 | ide_end_drive_cmd(drive, 0, 0); |
865 | 632 | ||
866 | if (remove_stage) | ||
867 | idetape_remove_stage_head(drive); | ||
868 | if (tape->active_data_rq == NULL) | ||
869 | clear_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags); | ||
870 | spin_unlock_irqrestore(&tape->lock, flags); | 633 | spin_unlock_irqrestore(&tape->lock, flags); |
871 | return 0; | 634 | return 0; |
872 | } | 635 | } |
@@ -1083,10 +846,10 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive) | |||
1083 | return ide_do_reset(drive); | 846 | return ide_do_reset(drive); |
1084 | } | 847 | } |
1085 | /* Get the number of bytes to transfer on this interrupt. */ | 848 | /* Get the number of bytes to transfer on this interrupt. */ |
1086 | bcount = (hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]) << 8) | | 849 | bcount = (hwif->INB(hwif->io_ports.lbah_addr) << 8) | |
1087 | hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); | 850 | hwif->INB(hwif->io_ports.lbam_addr); |
1088 | 851 | ||
1089 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); | 852 | ireason = hwif->INB(hwif->io_ports.nsect_addr); |
1090 | 853 | ||
1091 | if (ireason & CD) { | 854 | if (ireason & CD) { |
1092 | printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__); | 855 | printk(KERN_ERR "ide-tape: CoD != 0 in %s\n", __func__); |
@@ -1190,12 +953,12 @@ static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive) | |||
1190 | "yet DRQ isn't asserted\n"); | 953 | "yet DRQ isn't asserted\n"); |
1191 | return startstop; | 954 | return startstop; |
1192 | } | 955 | } |
1193 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); | 956 | ireason = hwif->INB(hwif->io_ports.nsect_addr); |
1194 | while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) { | 957 | while (retries-- && ((ireason & CD) == 0 || (ireason & IO))) { |
1195 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing " | 958 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing " |
1196 | "a packet command, retrying\n"); | 959 | "a packet command, retrying\n"); |
1197 | udelay(100); | 960 | udelay(100); |
1198 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); | 961 | ireason = hwif->INB(hwif->io_ports.nsect_addr); |
1199 | if (retries == 0) { | 962 | if (retries == 0) { |
1200 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while " | 963 | printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while " |
1201 | "issuing a packet command, ignoring\n"); | 964 | "issuing a packet command, ignoring\n"); |
@@ -1292,7 +1055,7 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, | |||
1292 | IDETAPE_WAIT_CMD, NULL); | 1055 | IDETAPE_WAIT_CMD, NULL); |
1293 | return ide_started; | 1056 | return ide_started; |
1294 | } else { | 1057 | } else { |
1295 | hwif->OUTB(WIN_PACKETCMD, hwif->io_ports[IDE_COMMAND_OFFSET]); | 1058 | hwif->OUTB(WIN_PACKETCMD, hwif->io_ports.command_addr); |
1296 | return idetape_transfer_pc(drive); | 1059 | return idetape_transfer_pc(drive); |
1297 | } | 1060 | } |
1298 | } | 1061 | } |
@@ -1335,69 +1098,6 @@ static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) | |||
1335 | pc->idetape_callback = &idetape_pc_callback; | 1098 | pc->idetape_callback = &idetape_pc_callback; |
1336 | } | 1099 | } |
1337 | 1100 | ||
1338 | static void idetape_calculate_speeds(ide_drive_t *drive) | ||
1339 | { | ||
1340 | idetape_tape_t *tape = drive->driver_data; | ||
1341 | |||
1342 | if (time_after(jiffies, | ||
1343 | tape->controlled_pipeline_head_time + 120 * HZ)) { | ||
1344 | tape->controlled_previous_pipeline_head = | ||
1345 | tape->controlled_last_pipeline_head; | ||
1346 | tape->controlled_previous_head_time = | ||
1347 | tape->controlled_pipeline_head_time; | ||
1348 | tape->controlled_last_pipeline_head = tape->pipeline_head; | ||
1349 | tape->controlled_pipeline_head_time = jiffies; | ||
1350 | } | ||
1351 | if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ)) | ||
1352 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - | ||
1353 | tape->controlled_last_pipeline_head) * 32 * HZ / | ||
1354 | (jiffies - tape->controlled_pipeline_head_time); | ||
1355 | else if (time_after(jiffies, tape->controlled_previous_head_time)) | ||
1356 | tape->controlled_pipeline_head_speed = (tape->pipeline_head - | ||
1357 | tape->controlled_previous_pipeline_head) * 32 * | ||
1358 | HZ / (jiffies - tape->controlled_previous_head_time); | ||
1359 | |||
1360 | if (tape->nr_pending_stages < tape->max_stages/*- 1 */) { | ||
1361 | /* -1 for read mode error recovery */ | ||
1362 | if (time_after(jiffies, tape->uncontrolled_previous_head_time + | ||
1363 | 10 * HZ)) { | ||
1364 | tape->uncontrolled_pipeline_head_time = jiffies; | ||
1365 | tape->uncontrolled_pipeline_head_speed = | ||
1366 | (tape->pipeline_head - | ||
1367 | tape->uncontrolled_previous_pipeline_head) * | ||
1368 | 32 * HZ / (jiffies - | ||
1369 | tape->uncontrolled_previous_head_time); | ||
1370 | } | ||
1371 | } else { | ||
1372 | tape->uncontrolled_previous_head_time = jiffies; | ||
1373 | tape->uncontrolled_previous_pipeline_head = tape->pipeline_head; | ||
1374 | if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + | ||
1375 | 30 * HZ)) | ||
1376 | tape->uncontrolled_pipeline_head_time = jiffies; | ||
1377 | |||
1378 | } | ||
1379 | tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, | ||
1380 | tape->controlled_pipeline_head_speed); | ||
1381 | |||
1382 | if (tape->speed_control == 1) { | ||
1383 | if (tape->nr_pending_stages >= tape->max_stages / 2) | ||
1384 | tape->max_insert_speed = tape->pipeline_head_speed + | ||
1385 | (1100 - tape->pipeline_head_speed) * 2 * | ||
1386 | (tape->nr_pending_stages - tape->max_stages / 2) | ||
1387 | / tape->max_stages; | ||
1388 | else | ||
1389 | tape->max_insert_speed = 500 + | ||
1390 | (tape->pipeline_head_speed - 500) * 2 * | ||
1391 | tape->nr_pending_stages / tape->max_stages; | ||
1392 | |||
1393 | if (tape->nr_pending_stages >= tape->max_stages * 99 / 100) | ||
1394 | tape->max_insert_speed = 5000; | ||
1395 | } else | ||
1396 | tape->max_insert_speed = tape->speed_control; | ||
1397 | |||
1398 | tape->max_insert_speed = max(tape->max_insert_speed, 500); | ||
1399 | } | ||
1400 | |||
1401 | static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) | 1101 | static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) |
1402 | { | 1102 | { |
1403 | idetape_tape_t *tape = drive->driver_data; | 1103 | idetape_tape_t *tape = drive->driver_data; |
@@ -1432,17 +1132,7 @@ static ide_startstop_t idetape_rw_callback(ide_drive_t *drive) | |||
1432 | int blocks = tape->pc->xferred / tape->blk_size; | 1132 | int blocks = tape->pc->xferred / tape->blk_size; |
1433 | 1133 | ||
1434 | tape->avg_size += blocks * tape->blk_size; | 1134 | tape->avg_size += blocks * tape->blk_size; |
1435 | tape->insert_size += blocks * tape->blk_size; | 1135 | |
1436 | if (tape->insert_size > 1024 * 1024) | ||
1437 | tape->measure_insert_time = 1; | ||
1438 | if (tape->measure_insert_time) { | ||
1439 | tape->measure_insert_time = 0; | ||
1440 | tape->insert_time = jiffies; | ||
1441 | tape->insert_size = 0; | ||
1442 | } | ||
1443 | if (time_after(jiffies, tape->insert_time)) | ||
1444 | tape->insert_speed = tape->insert_size / 1024 * HZ / | ||
1445 | (jiffies - tape->insert_time); | ||
1446 | if (time_after_eq(jiffies, tape->avg_time + HZ)) { | 1136 | if (time_after_eq(jiffies, tape->avg_time + HZ)) { |
1447 | tape->avg_speed = tape->avg_size * HZ / | 1137 | tape->avg_speed = tape->avg_size * HZ / |
1448 | (jiffies - tape->avg_time) / 1024; | 1138 | (jiffies - tape->avg_time) / 1024; |
@@ -1475,7 +1165,7 @@ static void idetape_create_read_cmd(idetape_tape_t *tape, | |||
1475 | pc->buf = NULL; | 1165 | pc->buf = NULL; |
1476 | pc->buf_size = length * tape->blk_size; | 1166 | pc->buf_size = length * tape->blk_size; |
1477 | pc->req_xfer = pc->buf_size; | 1167 | pc->req_xfer = pc->buf_size; |
1478 | if (pc->req_xfer == tape->stage_size) | 1168 | if (pc->req_xfer == tape->buffer_size) |
1479 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; | 1169 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
1480 | } | 1170 | } |
1481 | 1171 | ||
@@ -1495,7 +1185,7 @@ static void idetape_create_write_cmd(idetape_tape_t *tape, | |||
1495 | pc->buf = NULL; | 1185 | pc->buf = NULL; |
1496 | pc->buf_size = length * tape->blk_size; | 1186 | pc->buf_size = length * tape->blk_size; |
1497 | pc->req_xfer = pc->buf_size; | 1187 | pc->req_xfer = pc->buf_size; |
1498 | if (pc->req_xfer == tape->stage_size) | 1188 | if (pc->req_xfer == tape->buffer_size) |
1499 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; | 1189 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
1500 | } | 1190 | } |
1501 | 1191 | ||
@@ -1547,10 +1237,6 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive, | |||
1547 | drive->post_reset = 0; | 1237 | drive->post_reset = 0; |
1548 | } | 1238 | } |
1549 | 1239 | ||
1550 | if (time_after(jiffies, tape->insert_time)) | ||
1551 | tape->insert_speed = tape->insert_size / 1024 * HZ / | ||
1552 | (jiffies - tape->insert_time); | ||
1553 | idetape_calculate_speeds(drive); | ||
1554 | if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) && | 1240 | if (!test_and_clear_bit(IDETAPE_FLAG_IGNORE_DSC, &tape->flags) && |
1555 | (stat & SEEK_STAT) == 0) { | 1241 | (stat & SEEK_STAT) == 0) { |
1556 | if (postponed_rq == NULL) { | 1242 | if (postponed_rq == NULL) { |
@@ -1574,16 +1260,12 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive, | |||
1574 | return ide_stopped; | 1260 | return ide_stopped; |
1575 | } | 1261 | } |
1576 | if (rq->cmd[0] & REQ_IDETAPE_READ) { | 1262 | if (rq->cmd[0] & REQ_IDETAPE_READ) { |
1577 | tape->buffer_head++; | ||
1578 | tape->postpone_cnt = 0; | ||
1579 | pc = idetape_next_pc_storage(drive); | 1263 | pc = idetape_next_pc_storage(drive); |
1580 | idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, | 1264 | idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, |
1581 | (struct idetape_bh *)rq->special); | 1265 | (struct idetape_bh *)rq->special); |
1582 | goto out; | 1266 | goto out; |
1583 | } | 1267 | } |
1584 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { | 1268 | if (rq->cmd[0] & REQ_IDETAPE_WRITE) { |
1585 | tape->buffer_head++; | ||
1586 | tape->postpone_cnt = 0; | ||
1587 | pc = idetape_next_pc_storage(drive); | 1269 | pc = idetape_next_pc_storage(drive); |
1588 | idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, | 1270 | idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, |
1589 | (struct idetape_bh *)rq->special); | 1271 | (struct idetape_bh *)rq->special); |
@@ -1604,103 +1286,91 @@ out: | |||
1604 | return idetape_issue_pc(drive, pc); | 1286 | return idetape_issue_pc(drive, pc); |
1605 | } | 1287 | } |
1606 | 1288 | ||
1607 | /* Pipeline related functions */ | ||
1608 | |||
1609 | /* | 1289 | /* |
1610 | * The function below uses __get_free_page to allocate a pipeline stage, along | 1290 | * The function below uses __get_free_pages to allocate a data buffer of size |
1611 | * with all the necessary small buffers which together make a buffer of size | 1291 | * tape->buffer_size (or a bit more). We attempt to combine sequential pages as |
1612 | * tape->stage_size (or a bit more). We attempt to combine sequential pages as | ||
1613 | * much as possible. | 1292 | * much as possible. |
1614 | * | 1293 | * |
1615 | * It returns a pointer to the new allocated stage, or NULL if we can't (or | 1294 | * It returns a pointer to the newly allocated buffer, or NULL in case of |
1616 | * don't want to) allocate a stage. | 1295 | * failure. |
1617 | * | ||
1618 | * Pipeline stages are optional and are used to increase performance. If we | ||
1619 | * can't allocate them, we'll manage without them. | ||
1620 | */ | 1296 | */ |
1621 | static idetape_stage_t *__idetape_kmalloc_stage(idetape_tape_t *tape, int full, | 1297 | static struct idetape_bh *ide_tape_kmalloc_buffer(idetape_tape_t *tape, |
1622 | int clear) | 1298 | int full, int clear) |
1623 | { | 1299 | { |
1624 | idetape_stage_t *stage; | 1300 | struct idetape_bh *prev_bh, *bh, *merge_bh; |
1625 | struct idetape_bh *prev_bh, *bh; | 1301 | int pages = tape->pages_per_buffer; |
1626 | int pages = tape->pages_per_stage; | 1302 | unsigned int order, b_allocd; |
1627 | char *b_data = NULL; | 1303 | char *b_data = NULL; |
1628 | 1304 | ||
1629 | stage = kmalloc(sizeof(idetape_stage_t), GFP_KERNEL); | 1305 | merge_bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); |
1630 | if (!stage) | 1306 | bh = merge_bh; |
1631 | return NULL; | ||
1632 | stage->next = NULL; | ||
1633 | |||
1634 | stage->bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); | ||
1635 | bh = stage->bh; | ||
1636 | if (bh == NULL) | 1307 | if (bh == NULL) |
1637 | goto abort; | 1308 | goto abort; |
1638 | bh->b_reqnext = NULL; | 1309 | |
1639 | bh->b_data = (char *) __get_free_page(GFP_KERNEL); | 1310 | order = fls(pages) - 1; |
1311 | bh->b_data = (char *) __get_free_pages(GFP_KERNEL, order); | ||
1640 | if (!bh->b_data) | 1312 | if (!bh->b_data) |
1641 | goto abort; | 1313 | goto abort; |
1314 | b_allocd = (1 << order) * PAGE_SIZE; | ||
1315 | pages &= (order-1); | ||
1316 | |||
1642 | if (clear) | 1317 | if (clear) |
1643 | memset(bh->b_data, 0, PAGE_SIZE); | 1318 | memset(bh->b_data, 0, b_allocd); |
1644 | bh->b_size = PAGE_SIZE; | 1319 | bh->b_reqnext = NULL; |
1320 | bh->b_size = b_allocd; | ||
1645 | atomic_set(&bh->b_count, full ? bh->b_size : 0); | 1321 | atomic_set(&bh->b_count, full ? bh->b_size : 0); |
1646 | 1322 | ||
1647 | while (--pages) { | 1323 | while (pages) { |
1648 | b_data = (char *) __get_free_page(GFP_KERNEL); | 1324 | order = fls(pages) - 1; |
1325 | b_data = (char *) __get_free_pages(GFP_KERNEL, order); | ||
1649 | if (!b_data) | 1326 | if (!b_data) |
1650 | goto abort; | 1327 | goto abort; |
1328 | b_allocd = (1 << order) * PAGE_SIZE; | ||
1329 | |||
1651 | if (clear) | 1330 | if (clear) |
1652 | memset(b_data, 0, PAGE_SIZE); | 1331 | memset(b_data, 0, b_allocd); |
1653 | if (bh->b_data == b_data + PAGE_SIZE) { | 1332 | |
1654 | bh->b_size += PAGE_SIZE; | 1333 | /* newly allocated page frames below buffer header or ...*/ |
1655 | bh->b_data -= PAGE_SIZE; | 1334 | if (bh->b_data == b_data + b_allocd) { |
1335 | bh->b_size += b_allocd; | ||
1336 | bh->b_data -= b_allocd; | ||
1656 | if (full) | 1337 | if (full) |
1657 | atomic_add(PAGE_SIZE, &bh->b_count); | 1338 | atomic_add(b_allocd, &bh->b_count); |
1658 | continue; | 1339 | continue; |
1659 | } | 1340 | } |
1341 | /* they are above the header */ | ||
1660 | if (b_data == bh->b_data + bh->b_size) { | 1342 | if (b_data == bh->b_data + bh->b_size) { |
1661 | bh->b_size += PAGE_SIZE; | 1343 | bh->b_size += b_allocd; |
1662 | if (full) | 1344 | if (full) |
1663 | atomic_add(PAGE_SIZE, &bh->b_count); | 1345 | atomic_add(b_allocd, &bh->b_count); |
1664 | continue; | 1346 | continue; |
1665 | } | 1347 | } |
1666 | prev_bh = bh; | 1348 | prev_bh = bh; |
1667 | bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); | 1349 | bh = kmalloc(sizeof(struct idetape_bh), GFP_KERNEL); |
1668 | if (!bh) { | 1350 | if (!bh) { |
1669 | free_page((unsigned long) b_data); | 1351 | free_pages((unsigned long) b_data, order); |
1670 | goto abort; | 1352 | goto abort; |
1671 | } | 1353 | } |
1672 | bh->b_reqnext = NULL; | 1354 | bh->b_reqnext = NULL; |
1673 | bh->b_data = b_data; | 1355 | bh->b_data = b_data; |
1674 | bh->b_size = PAGE_SIZE; | 1356 | bh->b_size = b_allocd; |
1675 | atomic_set(&bh->b_count, full ? bh->b_size : 0); | 1357 | atomic_set(&bh->b_count, full ? bh->b_size : 0); |
1676 | prev_bh->b_reqnext = bh; | 1358 | prev_bh->b_reqnext = bh; |
1359 | |||
1360 | pages &= (order-1); | ||
1677 | } | 1361 | } |
1362 | |||
1678 | bh->b_size -= tape->excess_bh_size; | 1363 | bh->b_size -= tape->excess_bh_size; |
1679 | if (full) | 1364 | if (full) |
1680 | atomic_sub(tape->excess_bh_size, &bh->b_count); | 1365 | atomic_sub(tape->excess_bh_size, &bh->b_count); |
1681 | return stage; | 1366 | return merge_bh; |
1682 | abort: | 1367 | abort: |
1683 | __idetape_kfree_stage(stage); | 1368 | ide_tape_kfree_buffer(tape); |
1684 | return NULL; | 1369 | return NULL; |
1685 | } | 1370 | } |
1686 | 1371 | ||
1687 | static idetape_stage_t *idetape_kmalloc_stage(idetape_tape_t *tape) | ||
1688 | { | ||
1689 | idetape_stage_t *cache_stage = tape->cache_stage; | ||
1690 | |||
1691 | debug_log(DBG_PROCS, "Enter %s\n", __func__); | ||
1692 | |||
1693 | if (tape->nr_stages >= tape->max_stages) | ||
1694 | return NULL; | ||
1695 | if (cache_stage != NULL) { | ||
1696 | tape->cache_stage = NULL; | ||
1697 | return cache_stage; | ||
1698 | } | ||
1699 | return __idetape_kmalloc_stage(tape, 0, 0); | ||
1700 | } | ||
1701 | |||
1702 | static int idetape_copy_stage_from_user(idetape_tape_t *tape, | 1372 | static int idetape_copy_stage_from_user(idetape_tape_t *tape, |
1703 | idetape_stage_t *stage, const char __user *buf, int n) | 1373 | const char __user *buf, int n) |
1704 | { | 1374 | { |
1705 | struct idetape_bh *bh = tape->bh; | 1375 | struct idetape_bh *bh = tape->bh; |
1706 | int count; | 1376 | int count; |
@@ -1732,7 +1402,7 @@ static int idetape_copy_stage_from_user(idetape_tape_t *tape, | |||
1732 | } | 1402 | } |
1733 | 1403 | ||
1734 | static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf, | 1404 | static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf, |
1735 | idetape_stage_t *stage, int n) | 1405 | int n) |
1736 | { | 1406 | { |
1737 | struct idetape_bh *bh = tape->bh; | 1407 | struct idetape_bh *bh = tape->bh; |
1738 | int count; | 1408 | int count; |
@@ -1763,11 +1433,11 @@ static int idetape_copy_stage_to_user(idetape_tape_t *tape, char __user *buf, | |||
1763 | return ret; | 1433 | return ret; |
1764 | } | 1434 | } |
1765 | 1435 | ||
1766 | static void idetape_init_merge_stage(idetape_tape_t *tape) | 1436 | static void idetape_init_merge_buffer(idetape_tape_t *tape) |
1767 | { | 1437 | { |
1768 | struct idetape_bh *bh = tape->merge_stage->bh; | 1438 | struct idetape_bh *bh = tape->merge_bh; |
1439 | tape->bh = tape->merge_bh; | ||
1769 | 1440 | ||
1770 | tape->bh = bh; | ||
1771 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) | 1441 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) |
1772 | atomic_set(&bh->b_count, 0); | 1442 | atomic_set(&bh->b_count, 0); |
1773 | else { | 1443 | else { |
@@ -1776,61 +1446,6 @@ static void idetape_init_merge_stage(idetape_tape_t *tape) | |||
1776 | } | 1446 | } |
1777 | } | 1447 | } |
1778 | 1448 | ||
1779 | static void idetape_switch_buffers(idetape_tape_t *tape, idetape_stage_t *stage) | ||
1780 | { | ||
1781 | struct idetape_bh *tmp; | ||
1782 | |||
1783 | tmp = stage->bh; | ||
1784 | stage->bh = tape->merge_stage->bh; | ||
1785 | tape->merge_stage->bh = tmp; | ||
1786 | idetape_init_merge_stage(tape); | ||
1787 | } | ||
1788 | |||
1789 | /* Add a new stage at the end of the pipeline. */ | ||
1790 | static void idetape_add_stage_tail(ide_drive_t *drive, idetape_stage_t *stage) | ||
1791 | { | ||
1792 | idetape_tape_t *tape = drive->driver_data; | ||
1793 | unsigned long flags; | ||
1794 | |||
1795 | debug_log(DBG_PROCS, "Enter %s\n", __func__); | ||
1796 | |||
1797 | spin_lock_irqsave(&tape->lock, flags); | ||
1798 | stage->next = NULL; | ||
1799 | if (tape->last_stage != NULL) | ||
1800 | tape->last_stage->next = stage; | ||
1801 | else | ||
1802 | tape->first_stage = stage; | ||
1803 | tape->next_stage = stage; | ||
1804 | tape->last_stage = stage; | ||
1805 | if (tape->next_stage == NULL) | ||
1806 | tape->next_stage = tape->last_stage; | ||
1807 | tape->nr_stages++; | ||
1808 | tape->nr_pending_stages++; | ||
1809 | spin_unlock_irqrestore(&tape->lock, flags); | ||
1810 | } | ||
1811 | |||
1812 | /* Install a completion in a pending request and sleep until it is serviced. The | ||
1813 | * caller should ensure that the request will not be serviced before we install | ||
1814 | * the completion (usually by disabling interrupts). | ||
1815 | */ | ||
1816 | static void idetape_wait_for_request(ide_drive_t *drive, struct request *rq) | ||
1817 | { | ||
1818 | DECLARE_COMPLETION_ONSTACK(wait); | ||
1819 | idetape_tape_t *tape = drive->driver_data; | ||
1820 | |||
1821 | if (rq == NULL || !blk_special_request(rq)) { | ||
1822 | printk(KERN_ERR "ide-tape: bug: Trying to sleep on non-valid" | ||
1823 | " request\n"); | ||
1824 | return; | ||
1825 | } | ||
1826 | rq->end_io_data = &wait; | ||
1827 | rq->end_io = blk_end_sync_rq; | ||
1828 | spin_unlock_irq(&tape->lock); | ||
1829 | wait_for_completion(&wait); | ||
1830 | /* The stage and its struct request have been deallocated */ | ||
1831 | spin_lock_irq(&tape->lock); | ||
1832 | } | ||
1833 | |||
1834 | static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive) | 1449 | static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive) |
1835 | { | 1450 | { |
1836 | idetape_tape_t *tape = drive->driver_data; | 1451 | idetape_tape_t *tape = drive->driver_data; |
@@ -1899,7 +1514,7 @@ static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) | |||
1899 | * to the request list without waiting for it to be serviced! In that case, we | 1514 | * to the request list without waiting for it to be serviced! In that case, we |
1900 | * usually use idetape_queue_pc_head(). | 1515 | * usually use idetape_queue_pc_head(). |
1901 | */ | 1516 | */ |
1902 | static int __idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) | 1517 | static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) |
1903 | { | 1518 | { |
1904 | struct ide_tape_obj *tape = drive->driver_data; | 1519 | struct ide_tape_obj *tape = drive->driver_data; |
1905 | struct request rq; | 1520 | struct request rq; |
@@ -1931,7 +1546,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | |||
1931 | timeout += jiffies; | 1546 | timeout += jiffies; |
1932 | while (time_before(jiffies, timeout)) { | 1547 | while (time_before(jiffies, timeout)) { |
1933 | idetape_create_test_unit_ready_cmd(&pc); | 1548 | idetape_create_test_unit_ready_cmd(&pc); |
1934 | if (!__idetape_queue_pc_tail(drive, &pc)) | 1549 | if (!idetape_queue_pc_tail(drive, &pc)) |
1935 | return 0; | 1550 | return 0; |
1936 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) | 1551 | if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2) |
1937 | || (tape->asc == 0x3A)) { | 1552 | || (tape->asc == 0x3A)) { |
@@ -1940,7 +1555,7 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | |||
1940 | return -ENOMEDIUM; | 1555 | return -ENOMEDIUM; |
1941 | idetape_create_load_unload_cmd(drive, &pc, | 1556 | idetape_create_load_unload_cmd(drive, &pc, |
1942 | IDETAPE_LU_LOAD_MASK); | 1557 | IDETAPE_LU_LOAD_MASK); |
1943 | __idetape_queue_pc_tail(drive, &pc); | 1558 | idetape_queue_pc_tail(drive, &pc); |
1944 | load_attempted = 1; | 1559 | load_attempted = 1; |
1945 | /* not about to be ready */ | 1560 | /* not about to be ready */ |
1946 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && | 1561 | } else if (!(tape->sense_key == 2 && tape->asc == 4 && |
@@ -1951,11 +1566,6 @@ static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) | |||
1951 | return -EIO; | 1566 | return -EIO; |
1952 | } | 1567 | } |
1953 | 1568 | ||
1954 | static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) | ||
1955 | { | ||
1956 | return __idetape_queue_pc_tail(drive, pc); | ||
1957 | } | ||
1958 | |||
1959 | static int idetape_flush_tape_buffers(ide_drive_t *drive) | 1569 | static int idetape_flush_tape_buffers(ide_drive_t *drive) |
1960 | { | 1570 | { |
1961 | struct ide_atapi_pc pc; | 1571 | struct ide_atapi_pc pc; |
@@ -2021,50 +1631,21 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive, | |||
2021 | return 1; | 1631 | return 1; |
2022 | } | 1632 | } |
2023 | 1633 | ||
2024 | static int __idetape_discard_read_pipeline(ide_drive_t *drive) | 1634 | static void __ide_tape_discard_merge_buffer(ide_drive_t *drive) |
2025 | { | 1635 | { |
2026 | idetape_tape_t *tape = drive->driver_data; | 1636 | idetape_tape_t *tape = drive->driver_data; |
2027 | unsigned long flags; | ||
2028 | int cnt; | ||
2029 | 1637 | ||
2030 | if (tape->chrdev_dir != IDETAPE_DIR_READ) | 1638 | if (tape->chrdev_dir != IDETAPE_DIR_READ) |
2031 | return 0; | 1639 | return; |
2032 | 1640 | ||
2033 | /* Remove merge stage. */ | 1641 | clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags); |
2034 | cnt = tape->merge_stage_size / tape->blk_size; | 1642 | tape->merge_bh_size = 0; |
2035 | if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) | 1643 | if (tape->merge_bh != NULL) { |
2036 | ++cnt; /* Filemarks count as 1 sector */ | 1644 | ide_tape_kfree_buffer(tape); |
2037 | tape->merge_stage_size = 0; | 1645 | tape->merge_bh = NULL; |
2038 | if (tape->merge_stage != NULL) { | ||
2039 | __idetape_kfree_stage(tape->merge_stage); | ||
2040 | tape->merge_stage = NULL; | ||
2041 | } | 1646 | } |
2042 | 1647 | ||
2043 | /* Clear pipeline flags. */ | ||
2044 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); | ||
2045 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 1648 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
2046 | |||
2047 | /* Remove pipeline stages. */ | ||
2048 | if (tape->first_stage == NULL) | ||
2049 | return 0; | ||
2050 | |||
2051 | spin_lock_irqsave(&tape->lock, flags); | ||
2052 | tape->next_stage = NULL; | ||
2053 | if (test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) | ||
2054 | idetape_wait_for_request(drive, tape->active_data_rq); | ||
2055 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2056 | |||
2057 | while (tape->first_stage != NULL) { | ||
2058 | struct request *rq_ptr = &tape->first_stage->rq; | ||
2059 | |||
2060 | cnt += rq_ptr->nr_sectors - rq_ptr->current_nr_sectors; | ||
2061 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) | ||
2062 | ++cnt; | ||
2063 | idetape_remove_stage_head(drive); | ||
2064 | } | ||
2065 | tape->nr_pending_stages = 0; | ||
2066 | tape->max_stages = tape->min_pipeline; | ||
2067 | return cnt; | ||
2068 | } | 1649 | } |
2069 | 1650 | ||
2070 | /* | 1651 | /* |
@@ -2081,7 +1662,7 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block, | |||
2081 | struct ide_atapi_pc pc; | 1662 | struct ide_atapi_pc pc; |
2082 | 1663 | ||
2083 | if (tape->chrdev_dir == IDETAPE_DIR_READ) | 1664 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
2084 | __idetape_discard_read_pipeline(drive); | 1665 | __ide_tape_discard_merge_buffer(drive); |
2085 | idetape_wait_ready(drive, 60 * 5 * HZ); | 1666 | idetape_wait_ready(drive, 60 * 5 * HZ); |
2086 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); | 1667 | idetape_create_locate_cmd(drive, &pc, block, partition, skip); |
2087 | retval = idetape_queue_pc_tail(drive, &pc); | 1668 | retval = idetape_queue_pc_tail(drive, &pc); |
@@ -2092,20 +1673,19 @@ static int idetape_position_tape(ide_drive_t *drive, unsigned int block, | |||
2092 | return (idetape_queue_pc_tail(drive, &pc)); | 1673 | return (idetape_queue_pc_tail(drive, &pc)); |
2093 | } | 1674 | } |
2094 | 1675 | ||
2095 | static void idetape_discard_read_pipeline(ide_drive_t *drive, | 1676 | static void ide_tape_discard_merge_buffer(ide_drive_t *drive, |
2096 | int restore_position) | 1677 | int restore_position) |
2097 | { | 1678 | { |
2098 | idetape_tape_t *tape = drive->driver_data; | 1679 | idetape_tape_t *tape = drive->driver_data; |
2099 | int cnt; | ||
2100 | int seek, position; | 1680 | int seek, position; |
2101 | 1681 | ||
2102 | cnt = __idetape_discard_read_pipeline(drive); | 1682 | __ide_tape_discard_merge_buffer(drive); |
2103 | if (restore_position) { | 1683 | if (restore_position) { |
2104 | position = idetape_read_position(drive); | 1684 | position = idetape_read_position(drive); |
2105 | seek = position > cnt ? position - cnt : 0; | 1685 | seek = position > 0 ? position : 0; |
2106 | if (idetape_position_tape(drive, seek, 0, 0)) { | 1686 | if (idetape_position_tape(drive, seek, 0, 0)) { |
2107 | printk(KERN_INFO "ide-tape: %s: position_tape failed in" | 1687 | printk(KERN_INFO "ide-tape: %s: position_tape failed in" |
2108 | " discard_pipeline()\n", tape->name); | 1688 | " %s\n", tape->name, __func__); |
2109 | return; | 1689 | return; |
2110 | } | 1690 | } |
2111 | } | 1691 | } |
@@ -2123,12 +1703,6 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, | |||
2123 | 1703 | ||
2124 | debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); | 1704 | debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); |
2125 | 1705 | ||
2126 | if (test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) { | ||
2127 | printk(KERN_ERR "ide-tape: bug: the pipeline is active in %s\n", | ||
2128 | __func__); | ||
2129 | return (0); | ||
2130 | } | ||
2131 | |||
2132 | idetape_init_rq(&rq, cmd); | 1706 | idetape_init_rq(&rq, cmd); |
2133 | rq.rq_disk = tape->disk; | 1707 | rq.rq_disk = tape->disk; |
2134 | rq.special = (void *)bh; | 1708 | rq.special = (void *)bh; |
@@ -2140,26 +1714,13 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks, | |||
2140 | if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) | 1714 | if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) |
2141 | return 0; | 1715 | return 0; |
2142 | 1716 | ||
2143 | if (tape->merge_stage) | 1717 | if (tape->merge_bh) |
2144 | idetape_init_merge_stage(tape); | 1718 | idetape_init_merge_buffer(tape); |
2145 | if (rq.errors == IDETAPE_ERROR_GENERAL) | 1719 | if (rq.errors == IDETAPE_ERROR_GENERAL) |
2146 | return -EIO; | 1720 | return -EIO; |
2147 | return (tape->blk_size * (blocks-rq.current_nr_sectors)); | 1721 | return (tape->blk_size * (blocks-rq.current_nr_sectors)); |
2148 | } | 1722 | } |
2149 | 1723 | ||
2150 | /* start servicing the pipeline stages, starting from tape->next_stage. */ | ||
2151 | static void idetape_plug_pipeline(ide_drive_t *drive) | ||
2152 | { | ||
2153 | idetape_tape_t *tape = drive->driver_data; | ||
2154 | |||
2155 | if (tape->next_stage == NULL) | ||
2156 | return; | ||
2157 | if (!test_and_set_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) { | ||
2158 | idetape_activate_next_stage(drive); | ||
2159 | (void) ide_do_drive_cmd(drive, tape->active_data_rq, ide_end); | ||
2160 | } | ||
2161 | } | ||
2162 | |||
2163 | static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) | 1724 | static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) |
2164 | { | 1725 | { |
2165 | idetape_init_pc(pc); | 1726 | idetape_init_pc(pc); |
@@ -2197,137 +1758,39 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) | |||
2197 | pc->idetape_callback = &idetape_pc_callback; | 1758 | pc->idetape_callback = &idetape_pc_callback; |
2198 | } | 1759 | } |
2199 | 1760 | ||
2200 | static void idetape_wait_first_stage(ide_drive_t *drive) | 1761 | /* Queue up a character device originated write request. */ |
2201 | { | ||
2202 | idetape_tape_t *tape = drive->driver_data; | ||
2203 | unsigned long flags; | ||
2204 | |||
2205 | if (tape->first_stage == NULL) | ||
2206 | return; | ||
2207 | spin_lock_irqsave(&tape->lock, flags); | ||
2208 | if (tape->active_stage == tape->first_stage) | ||
2209 | idetape_wait_for_request(drive, tape->active_data_rq); | ||
2210 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2211 | } | ||
2212 | |||
2213 | /* | ||
2214 | * Try to add a character device originated write request to our pipeline. In | ||
2215 | * case we don't succeed, we revert to non-pipelined operation mode for this | ||
2216 | * request. In order to accomplish that, we | ||
2217 | * | ||
2218 | * 1. Try to allocate a new pipeline stage. | ||
2219 | * 2. If we can't, wait for more and more requests to be serviced and try again | ||
2220 | * each time. | ||
2221 | * 3. If we still can't allocate a stage, fallback to non-pipelined operation | ||
2222 | * mode for this request. | ||
2223 | */ | ||
2224 | static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks) | 1762 | static int idetape_add_chrdev_write_request(ide_drive_t *drive, int blocks) |
2225 | { | 1763 | { |
2226 | idetape_tape_t *tape = drive->driver_data; | 1764 | idetape_tape_t *tape = drive->driver_data; |
2227 | idetape_stage_t *new_stage; | ||
2228 | unsigned long flags; | ||
2229 | struct request *rq; | ||
2230 | 1765 | ||
2231 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); | 1766 | debug_log(DBG_CHRDEV, "Enter %s\n", __func__); |
2232 | 1767 | ||
2233 | /* Attempt to allocate a new stage. Beware possible race conditions. */ | 1768 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, |
2234 | while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) { | 1769 | blocks, tape->merge_bh); |
2235 | spin_lock_irqsave(&tape->lock, flags); | ||
2236 | if (test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) { | ||
2237 | idetape_wait_for_request(drive, tape->active_data_rq); | ||
2238 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2239 | } else { | ||
2240 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2241 | idetape_plug_pipeline(drive); | ||
2242 | if (test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, | ||
2243 | &tape->flags)) | ||
2244 | continue; | ||
2245 | /* | ||
2246 | * The machine is short on memory. Fallback to non- | ||
2247 | * pipelined operation mode for this request. | ||
2248 | */ | ||
2249 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, | ||
2250 | blocks, tape->merge_stage->bh); | ||
2251 | } | ||
2252 | } | ||
2253 | rq = &new_stage->rq; | ||
2254 | idetape_init_rq(rq, REQ_IDETAPE_WRITE); | ||
2255 | /* Doesn't actually matter - We always assume sequential access */ | ||
2256 | rq->sector = tape->first_frame; | ||
2257 | rq->current_nr_sectors = blocks; | ||
2258 | rq->nr_sectors = blocks; | ||
2259 | |||
2260 | idetape_switch_buffers(tape, new_stage); | ||
2261 | idetape_add_stage_tail(drive, new_stage); | ||
2262 | tape->pipeline_head++; | ||
2263 | idetape_calculate_speeds(drive); | ||
2264 | |||
2265 | /* | ||
2266 | * Estimate whether the tape has stopped writing by checking if our | ||
2267 | * write pipeline is currently empty. If we are not writing anymore, | ||
2268 | * wait for the pipeline to be almost completely full (90%) before | ||
2269 | * starting to service requests, so that we will be able to keep up with | ||
2270 | * the higher speeds of the tape. | ||
2271 | */ | ||
2272 | if (!test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) { | ||
2273 | if (tape->nr_stages >= tape->max_stages * 9 / 10 || | ||
2274 | tape->nr_stages >= tape->max_stages - | ||
2275 | tape->uncontrolled_pipeline_head_speed * 3 * 1024 / | ||
2276 | tape->blk_size) { | ||
2277 | tape->measure_insert_time = 1; | ||
2278 | tape->insert_time = jiffies; | ||
2279 | tape->insert_size = 0; | ||
2280 | tape->insert_speed = 0; | ||
2281 | idetape_plug_pipeline(drive); | ||
2282 | } | ||
2283 | } | ||
2284 | if (test_and_clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags)) | ||
2285 | /* Return a deferred error */ | ||
2286 | return -EIO; | ||
2287 | return blocks; | ||
2288 | } | 1770 | } |
2289 | 1771 | ||
2290 | /* | 1772 | static void ide_tape_flush_merge_buffer(ide_drive_t *drive) |
2291 | * Wait until all pending pipeline requests are serviced. Typically called on | ||
2292 | * device close. | ||
2293 | */ | ||
2294 | static void idetape_wait_for_pipeline(ide_drive_t *drive) | ||
2295 | { | ||
2296 | idetape_tape_t *tape = drive->driver_data; | ||
2297 | unsigned long flags; | ||
2298 | |||
2299 | while (tape->next_stage || test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, | ||
2300 | &tape->flags)) { | ||
2301 | idetape_plug_pipeline(drive); | ||
2302 | spin_lock_irqsave(&tape->lock, flags); | ||
2303 | if (test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) | ||
2304 | idetape_wait_for_request(drive, tape->active_data_rq); | ||
2305 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2306 | } | ||
2307 | } | ||
2308 | |||
2309 | static void idetape_empty_write_pipeline(ide_drive_t *drive) | ||
2310 | { | 1773 | { |
2311 | idetape_tape_t *tape = drive->driver_data; | 1774 | idetape_tape_t *tape = drive->driver_data; |
2312 | int blocks, min; | 1775 | int blocks, min; |
2313 | struct idetape_bh *bh; | 1776 | struct idetape_bh *bh; |
2314 | 1777 | ||
2315 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { | 1778 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
2316 | printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline," | 1779 | printk(KERN_ERR "ide-tape: bug: Trying to empty merge buffer" |
2317 | " but we are not writing.\n"); | 1780 | " but we are not writing.\n"); |
2318 | return; | 1781 | return; |
2319 | } | 1782 | } |
2320 | if (tape->merge_stage_size > tape->stage_size) { | 1783 | if (tape->merge_bh_size > tape->buffer_size) { |
2321 | printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); | 1784 | printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n"); |
2322 | tape->merge_stage_size = tape->stage_size; | 1785 | tape->merge_bh_size = tape->buffer_size; |
2323 | } | 1786 | } |
2324 | if (tape->merge_stage_size) { | 1787 | if (tape->merge_bh_size) { |
2325 | blocks = tape->merge_stage_size / tape->blk_size; | 1788 | blocks = tape->merge_bh_size / tape->blk_size; |
2326 | if (tape->merge_stage_size % tape->blk_size) { | 1789 | if (tape->merge_bh_size % tape->blk_size) { |
2327 | unsigned int i; | 1790 | unsigned int i; |
2328 | 1791 | ||
2329 | blocks++; | 1792 | blocks++; |
2330 | i = tape->blk_size - tape->merge_stage_size % | 1793 | i = tape->blk_size - tape->merge_bh_size % |
2331 | tape->blk_size; | 1794 | tape->blk_size; |
2332 | bh = tape->bh->b_reqnext; | 1795 | bh = tape->bh->b_reqnext; |
2333 | while (bh) { | 1796 | while (bh) { |
@@ -2351,74 +1814,33 @@ static void idetape_empty_write_pipeline(ide_drive_t *drive) | |||
2351 | } | 1814 | } |
2352 | } | 1815 | } |
2353 | (void) idetape_add_chrdev_write_request(drive, blocks); | 1816 | (void) idetape_add_chrdev_write_request(drive, blocks); |
2354 | tape->merge_stage_size = 0; | 1817 | tape->merge_bh_size = 0; |
2355 | } | 1818 | } |
2356 | idetape_wait_for_pipeline(drive); | 1819 | if (tape->merge_bh != NULL) { |
2357 | if (tape->merge_stage != NULL) { | 1820 | ide_tape_kfree_buffer(tape); |
2358 | __idetape_kfree_stage(tape->merge_stage); | 1821 | tape->merge_bh = NULL; |
2359 | tape->merge_stage = NULL; | ||
2360 | } | 1822 | } |
2361 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); | ||
2362 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 1823 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
2363 | |||
2364 | /* | ||
2365 | * On the next backup, perform the feedback loop again. (I don't want to | ||
2366 | * keep sense information between backups, as some systems are | ||
2367 | * constantly on, and the system load can be totally different on the | ||
2368 | * next backup). | ||
2369 | */ | ||
2370 | tape->max_stages = tape->min_pipeline; | ||
2371 | if (tape->first_stage != NULL || | ||
2372 | tape->next_stage != NULL || | ||
2373 | tape->last_stage != NULL || | ||
2374 | tape->nr_stages != 0) { | ||
2375 | printk(KERN_ERR "ide-tape: ide-tape pipeline bug, " | ||
2376 | "first_stage %p, next_stage %p, " | ||
2377 | "last_stage %p, nr_stages %d\n", | ||
2378 | tape->first_stage, tape->next_stage, | ||
2379 | tape->last_stage, tape->nr_stages); | ||
2380 | } | ||
2381 | } | 1824 | } |
2382 | 1825 | ||
2383 | static void idetape_restart_speed_control(ide_drive_t *drive) | 1826 | static int idetape_init_read(ide_drive_t *drive) |
2384 | { | 1827 | { |
2385 | idetape_tape_t *tape = drive->driver_data; | 1828 | idetape_tape_t *tape = drive->driver_data; |
2386 | |||
2387 | tape->restart_speed_control_req = 0; | ||
2388 | tape->pipeline_head = 0; | ||
2389 | tape->controlled_last_pipeline_head = 0; | ||
2390 | tape->controlled_previous_pipeline_head = 0; | ||
2391 | tape->uncontrolled_previous_pipeline_head = 0; | ||
2392 | tape->controlled_pipeline_head_speed = 5000; | ||
2393 | tape->pipeline_head_speed = 5000; | ||
2394 | tape->uncontrolled_pipeline_head_speed = 0; | ||
2395 | tape->controlled_pipeline_head_time = | ||
2396 | tape->uncontrolled_pipeline_head_time = jiffies; | ||
2397 | tape->controlled_previous_head_time = | ||
2398 | tape->uncontrolled_previous_head_time = jiffies; | ||
2399 | } | ||
2400 | |||
2401 | static int idetape_init_read(ide_drive_t *drive, int max_stages) | ||
2402 | { | ||
2403 | idetape_tape_t *tape = drive->driver_data; | ||
2404 | idetape_stage_t *new_stage; | ||
2405 | struct request rq; | ||
2406 | int bytes_read; | 1829 | int bytes_read; |
2407 | u16 blocks = *(u16 *)&tape->caps[12]; | ||
2408 | 1830 | ||
2409 | /* Initialize read operation */ | 1831 | /* Initialize read operation */ |
2410 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { | 1832 | if (tape->chrdev_dir != IDETAPE_DIR_READ) { |
2411 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { | 1833 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
2412 | idetape_empty_write_pipeline(drive); | 1834 | ide_tape_flush_merge_buffer(drive); |
2413 | idetape_flush_tape_buffers(drive); | 1835 | idetape_flush_tape_buffers(drive); |
2414 | } | 1836 | } |
2415 | if (tape->merge_stage || tape->merge_stage_size) { | 1837 | if (tape->merge_bh || tape->merge_bh_size) { |
2416 | printk(KERN_ERR "ide-tape: merge_stage_size should be" | 1838 | printk(KERN_ERR "ide-tape: merge_bh_size should be" |
2417 | " 0 now\n"); | 1839 | " 0 now\n"); |
2418 | tape->merge_stage_size = 0; | 1840 | tape->merge_bh_size = 0; |
2419 | } | 1841 | } |
2420 | tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0); | 1842 | tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0); |
2421 | if (!tape->merge_stage) | 1843 | if (!tape->merge_bh) |
2422 | return -ENOMEM; | 1844 | return -ENOMEM; |
2423 | tape->chrdev_dir = IDETAPE_DIR_READ; | 1845 | tape->chrdev_dir = IDETAPE_DIR_READ; |
2424 | 1846 | ||
@@ -2431,54 +1853,23 @@ static int idetape_init_read(ide_drive_t *drive, int max_stages) | |||
2431 | if (drive->dsc_overlap) { | 1853 | if (drive->dsc_overlap) { |
2432 | bytes_read = idetape_queue_rw_tail(drive, | 1854 | bytes_read = idetape_queue_rw_tail(drive, |
2433 | REQ_IDETAPE_READ, 0, | 1855 | REQ_IDETAPE_READ, 0, |
2434 | tape->merge_stage->bh); | 1856 | tape->merge_bh); |
2435 | if (bytes_read < 0) { | 1857 | if (bytes_read < 0) { |
2436 | __idetape_kfree_stage(tape->merge_stage); | 1858 | ide_tape_kfree_buffer(tape); |
2437 | tape->merge_stage = NULL; | 1859 | tape->merge_bh = NULL; |
2438 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 1860 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
2439 | return bytes_read; | 1861 | return bytes_read; |
2440 | } | 1862 | } |
2441 | } | 1863 | } |
2442 | } | 1864 | } |
2443 | if (tape->restart_speed_control_req) | 1865 | |
2444 | idetape_restart_speed_control(drive); | ||
2445 | idetape_init_rq(&rq, REQ_IDETAPE_READ); | ||
2446 | rq.sector = tape->first_frame; | ||
2447 | rq.nr_sectors = blocks; | ||
2448 | rq.current_nr_sectors = blocks; | ||
2449 | if (!test_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags) && | ||
2450 | tape->nr_stages < max_stages) { | ||
2451 | new_stage = idetape_kmalloc_stage(tape); | ||
2452 | while (new_stage != NULL) { | ||
2453 | new_stage->rq = rq; | ||
2454 | idetape_add_stage_tail(drive, new_stage); | ||
2455 | if (tape->nr_stages >= max_stages) | ||
2456 | break; | ||
2457 | new_stage = idetape_kmalloc_stage(tape); | ||
2458 | } | ||
2459 | } | ||
2460 | if (!test_bit(IDETAPE_FLAG_PIPELINE_ACTIVE, &tape->flags)) { | ||
2461 | if (tape->nr_pending_stages >= 3 * max_stages / 4) { | ||
2462 | tape->measure_insert_time = 1; | ||
2463 | tape->insert_time = jiffies; | ||
2464 | tape->insert_size = 0; | ||
2465 | tape->insert_speed = 0; | ||
2466 | idetape_plug_pipeline(drive); | ||
2467 | } | ||
2468 | } | ||
2469 | return 0; | 1866 | return 0; |
2470 | } | 1867 | } |
2471 | 1868 | ||
2472 | /* | 1869 | /* called from idetape_chrdev_read() to service a chrdev read request. */ |
2473 | * Called from idetape_chrdev_read() to service a character device read request | ||
2474 | * and add read-ahead requests to our pipeline. | ||
2475 | */ | ||
2476 | static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) | 1870 | static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) |
2477 | { | 1871 | { |
2478 | idetape_tape_t *tape = drive->driver_data; | 1872 | idetape_tape_t *tape = drive->driver_data; |
2479 | unsigned long flags; | ||
2480 | struct request *rq_ptr; | ||
2481 | int bytes_read; | ||
2482 | 1873 | ||
2483 | debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); | 1874 | debug_log(DBG_PROCS, "Enter %s, %d blocks\n", __func__, blocks); |
2484 | 1875 | ||
@@ -2486,39 +1877,10 @@ static int idetape_add_chrdev_read_request(ide_drive_t *drive, int blocks) | |||
2486 | if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) | 1877 | if (test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) |
2487 | return 0; | 1878 | return 0; |
2488 | 1879 | ||
2489 | /* Wait for the next block to reach the head of the pipeline. */ | 1880 | idetape_init_read(drive); |
2490 | idetape_init_read(drive, tape->max_stages); | ||
2491 | if (tape->first_stage == NULL) { | ||
2492 | if (test_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags)) | ||
2493 | return 0; | ||
2494 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, | ||
2495 | tape->merge_stage->bh); | ||
2496 | } | ||
2497 | idetape_wait_first_stage(drive); | ||
2498 | rq_ptr = &tape->first_stage->rq; | ||
2499 | bytes_read = tape->blk_size * (rq_ptr->nr_sectors - | ||
2500 | rq_ptr->current_nr_sectors); | ||
2501 | rq_ptr->nr_sectors = 0; | ||
2502 | rq_ptr->current_nr_sectors = 0; | ||
2503 | 1881 | ||
2504 | if (rq_ptr->errors == IDETAPE_ERROR_EOD) | 1882 | return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, |
2505 | return 0; | 1883 | tape->merge_bh); |
2506 | else { | ||
2507 | idetape_switch_buffers(tape, tape->first_stage); | ||
2508 | if (rq_ptr->errors == IDETAPE_ERROR_FILEMARK) | ||
2509 | set_bit(IDETAPE_FLAG_FILEMARK, &tape->flags); | ||
2510 | spin_lock_irqsave(&tape->lock, flags); | ||
2511 | idetape_remove_stage_head(drive); | ||
2512 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2513 | tape->pipeline_head++; | ||
2514 | idetape_calculate_speeds(drive); | ||
2515 | } | ||
2516 | if (bytes_read > blocks * tape->blk_size) { | ||
2517 | printk(KERN_ERR "ide-tape: bug: trying to return more bytes" | ||
2518 | " than requested\n"); | ||
2519 | bytes_read = blocks * tape->blk_size; | ||
2520 | } | ||
2521 | return (bytes_read); | ||
2522 | } | 1884 | } |
2523 | 1885 | ||
2524 | static void idetape_pad_zeros(ide_drive_t *drive, int bcount) | 1886 | static void idetape_pad_zeros(ide_drive_t *drive, int bcount) |
@@ -2530,8 +1892,8 @@ static void idetape_pad_zeros(ide_drive_t *drive, int bcount) | |||
2530 | while (bcount) { | 1892 | while (bcount) { |
2531 | unsigned int count; | 1893 | unsigned int count; |
2532 | 1894 | ||
2533 | bh = tape->merge_stage->bh; | 1895 | bh = tape->merge_bh; |
2534 | count = min(tape->stage_size, bcount); | 1896 | count = min(tape->buffer_size, bcount); |
2535 | bcount -= count; | 1897 | bcount -= count; |
2536 | blocks = count / tape->blk_size; | 1898 | blocks = count / tape->blk_size; |
2537 | while (count) { | 1899 | while (count) { |
@@ -2542,29 +1904,8 @@ static void idetape_pad_zeros(ide_drive_t *drive, int bcount) | |||
2542 | bh = bh->b_reqnext; | 1904 | bh = bh->b_reqnext; |
2543 | } | 1905 | } |
2544 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, | 1906 | idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, |
2545 | tape->merge_stage->bh); | 1907 | tape->merge_bh); |
2546 | } | ||
2547 | } | ||
2548 | |||
2549 | static int idetape_pipeline_size(ide_drive_t *drive) | ||
2550 | { | ||
2551 | idetape_tape_t *tape = drive->driver_data; | ||
2552 | idetape_stage_t *stage; | ||
2553 | struct request *rq; | ||
2554 | int size = 0; | ||
2555 | |||
2556 | idetape_wait_for_pipeline(drive); | ||
2557 | stage = tape->first_stage; | ||
2558 | while (stage != NULL) { | ||
2559 | rq = &stage->rq; | ||
2560 | size += tape->blk_size * (rq->nr_sectors - | ||
2561 | rq->current_nr_sectors); | ||
2562 | if (rq->errors == IDETAPE_ERROR_FILEMARK) | ||
2563 | size += tape->blk_size; | ||
2564 | stage = stage->next; | ||
2565 | } | 1908 | } |
2566 | size += tape->merge_stage_size; | ||
2567 | return size; | ||
2568 | } | 1909 | } |
2569 | 1910 | ||
2570 | /* | 1911 | /* |
@@ -2612,11 +1953,10 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, | |||
2612 | if (copy_from_user(&config, argp, sizeof(config))) | 1953 | if (copy_from_user(&config, argp, sizeof(config))) |
2613 | return -EFAULT; | 1954 | return -EFAULT; |
2614 | tape->best_dsc_rw_freq = config.dsc_rw_frequency; | 1955 | tape->best_dsc_rw_freq = config.dsc_rw_frequency; |
2615 | tape->max_stages = config.nr_stages; | ||
2616 | break; | 1956 | break; |
2617 | case 0x0350: | 1957 | case 0x0350: |
2618 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; | 1958 | config.dsc_rw_frequency = (int) tape->best_dsc_rw_freq; |
2619 | config.nr_stages = tape->max_stages; | 1959 | config.nr_stages = 1; |
2620 | if (copy_to_user(argp, &config, sizeof(config))) | 1960 | if (copy_to_user(argp, &config, sizeof(config))) |
2621 | return -EFAULT; | 1961 | return -EFAULT; |
2622 | break; | 1962 | break; |
@@ -2626,19 +1966,11 @@ static int idetape_blkdev_ioctl(ide_drive_t *drive, unsigned int cmd, | |||
2626 | return 0; | 1966 | return 0; |
2627 | } | 1967 | } |
2628 | 1968 | ||
2629 | /* | ||
2630 | * The function below is now a bit more complicated than just passing the | ||
2631 | * command to the tape since we may have crossed some filemarks during our | ||
2632 | * pipelined read-ahead mode. As a minor side effect, the pipeline enables us to | ||
2633 | * support MTFSFM when the filemark is in our internal pipeline even if the tape | ||
2634 | * doesn't support spacing over filemarks in the reverse direction. | ||
2635 | */ | ||
2636 | static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, | 1969 | static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, |
2637 | int mt_count) | 1970 | int mt_count) |
2638 | { | 1971 | { |
2639 | idetape_tape_t *tape = drive->driver_data; | 1972 | idetape_tape_t *tape = drive->driver_data; |
2640 | struct ide_atapi_pc pc; | 1973 | struct ide_atapi_pc pc; |
2641 | unsigned long flags; | ||
2642 | int retval, count = 0; | 1974 | int retval, count = 0; |
2643 | int sprev = !!(tape->caps[4] & 0x20); | 1975 | int sprev = !!(tape->caps[4] & 0x20); |
2644 | 1976 | ||
@@ -2651,48 +1983,12 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op, | |||
2651 | } | 1983 | } |
2652 | 1984 | ||
2653 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { | 1985 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
2654 | /* its a read-ahead buffer, scan it for crossed filemarks. */ | 1986 | tape->merge_bh_size = 0; |
2655 | tape->merge_stage_size = 0; | ||
2656 | if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) | 1987 | if (test_and_clear_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) |
2657 | ++count; | 1988 | ++count; |
2658 | while (tape->first_stage != NULL) { | 1989 | ide_tape_discard_merge_buffer(drive, 0); |
2659 | if (count == mt_count) { | ||
2660 | if (mt_op == MTFSFM) | ||
2661 | set_bit(IDETAPE_FLAG_FILEMARK, | ||
2662 | &tape->flags); | ||
2663 | return 0; | ||
2664 | } | ||
2665 | spin_lock_irqsave(&tape->lock, flags); | ||
2666 | if (tape->first_stage == tape->active_stage) { | ||
2667 | /* | ||
2668 | * We have reached the active stage in the read | ||
2669 | * pipeline. There is no point in allowing the | ||
2670 | * drive to continue reading any farther, so we | ||
2671 | * stop the pipeline. | ||
2672 | * | ||
2673 | * This section should be moved to a separate | ||
2674 | * subroutine because similar operations are | ||
2675 | * done in __idetape_discard_read_pipeline(), | ||
2676 | * for example. | ||
2677 | */ | ||
2678 | tape->next_stage = NULL; | ||
2679 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2680 | idetape_wait_first_stage(drive); | ||
2681 | tape->next_stage = tape->first_stage->next; | ||
2682 | } else | ||
2683 | spin_unlock_irqrestore(&tape->lock, flags); | ||
2684 | if (tape->first_stage->rq.errors == | ||
2685 | IDETAPE_ERROR_FILEMARK) | ||
2686 | ++count; | ||
2687 | idetape_remove_stage_head(drive); | ||
2688 | } | ||
2689 | idetape_discard_read_pipeline(drive, 0); | ||
2690 | } | 1990 | } |
2691 | 1991 | ||
2692 | /* | ||
2693 | * The filemark was not found in our internal pipeline; now we can issue | ||
2694 | * the space command. | ||
2695 | */ | ||
2696 | switch (mt_op) { | 1992 | switch (mt_op) { |
2697 | case MTFSF: | 1993 | case MTFSF: |
2698 | case MTBSF: | 1994 | case MTBSF: |
@@ -2748,27 +2044,25 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, | |||
2748 | (count % tape->blk_size) == 0) | 2044 | (count % tape->blk_size) == 0) |
2749 | tape->user_bs_factor = count / tape->blk_size; | 2045 | tape->user_bs_factor = count / tape->blk_size; |
2750 | } | 2046 | } |
2751 | rc = idetape_init_read(drive, tape->max_stages); | 2047 | rc = idetape_init_read(drive); |
2752 | if (rc < 0) | 2048 | if (rc < 0) |
2753 | return rc; | 2049 | return rc; |
2754 | if (count == 0) | 2050 | if (count == 0) |
2755 | return (0); | 2051 | return (0); |
2756 | if (tape->merge_stage_size) { | 2052 | if (tape->merge_bh_size) { |
2757 | actually_read = min((unsigned int)(tape->merge_stage_size), | 2053 | actually_read = min((unsigned int)(tape->merge_bh_size), |
2758 | (unsigned int)count); | 2054 | (unsigned int)count); |
2759 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, | 2055 | if (idetape_copy_stage_to_user(tape, buf, actually_read)) |
2760 | actually_read)) | ||
2761 | ret = -EFAULT; | 2056 | ret = -EFAULT; |
2762 | buf += actually_read; | 2057 | buf += actually_read; |
2763 | tape->merge_stage_size -= actually_read; | 2058 | tape->merge_bh_size -= actually_read; |
2764 | count -= actually_read; | 2059 | count -= actually_read; |
2765 | } | 2060 | } |
2766 | while (count >= tape->stage_size) { | 2061 | while (count >= tape->buffer_size) { |
2767 | bytes_read = idetape_add_chrdev_read_request(drive, ctl); | 2062 | bytes_read = idetape_add_chrdev_read_request(drive, ctl); |
2768 | if (bytes_read <= 0) | 2063 | if (bytes_read <= 0) |
2769 | goto finish; | 2064 | goto finish; |
2770 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, | 2065 | if (idetape_copy_stage_to_user(tape, buf, bytes_read)) |
2771 | bytes_read)) | ||
2772 | ret = -EFAULT; | 2066 | ret = -EFAULT; |
2773 | buf += bytes_read; | 2067 | buf += bytes_read; |
2774 | count -= bytes_read; | 2068 | count -= bytes_read; |
@@ -2779,11 +2073,10 @@ static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, | |||
2779 | if (bytes_read <= 0) | 2073 | if (bytes_read <= 0) |
2780 | goto finish; | 2074 | goto finish; |
2781 | temp = min((unsigned long)count, (unsigned long)bytes_read); | 2075 | temp = min((unsigned long)count, (unsigned long)bytes_read); |
2782 | if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, | 2076 | if (idetape_copy_stage_to_user(tape, buf, temp)) |
2783 | temp)) | ||
2784 | ret = -EFAULT; | 2077 | ret = -EFAULT; |
2785 | actually_read += temp; | 2078 | actually_read += temp; |
2786 | tape->merge_stage_size = bytes_read-temp; | 2079 | tape->merge_bh_size = bytes_read-temp; |
2787 | } | 2080 | } |
2788 | finish: | 2081 | finish: |
2789 | if (!actually_read && test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) { | 2082 | if (!actually_read && test_bit(IDETAPE_FLAG_FILEMARK, &tape->flags)) { |
@@ -2814,17 +2107,17 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, | |||
2814 | /* Initialize write operation */ | 2107 | /* Initialize write operation */ |
2815 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { | 2108 | if (tape->chrdev_dir != IDETAPE_DIR_WRITE) { |
2816 | if (tape->chrdev_dir == IDETAPE_DIR_READ) | 2109 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
2817 | idetape_discard_read_pipeline(drive, 1); | 2110 | ide_tape_discard_merge_buffer(drive, 1); |
2818 | if (tape->merge_stage || tape->merge_stage_size) { | 2111 | if (tape->merge_bh || tape->merge_bh_size) { |
2819 | printk(KERN_ERR "ide-tape: merge_stage_size " | 2112 | printk(KERN_ERR "ide-tape: merge_bh_size " |
2820 | "should be 0 now\n"); | 2113 | "should be 0 now\n"); |
2821 | tape->merge_stage_size = 0; | 2114 | tape->merge_bh_size = 0; |
2822 | } | 2115 | } |
2823 | tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0); | 2116 | tape->merge_bh = ide_tape_kmalloc_buffer(tape, 0, 0); |
2824 | if (!tape->merge_stage) | 2117 | if (!tape->merge_bh) |
2825 | return -ENOMEM; | 2118 | return -ENOMEM; |
2826 | tape->chrdev_dir = IDETAPE_DIR_WRITE; | 2119 | tape->chrdev_dir = IDETAPE_DIR_WRITE; |
2827 | idetape_init_merge_stage(tape); | 2120 | idetape_init_merge_buffer(tape); |
2828 | 2121 | ||
2829 | /* | 2122 | /* |
2830 | * Issue a write 0 command to ensure that DSC handshake is | 2123 | * Issue a write 0 command to ensure that DSC handshake is |
@@ -2835,10 +2128,10 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, | |||
2835 | if (drive->dsc_overlap) { | 2128 | if (drive->dsc_overlap) { |
2836 | ssize_t retval = idetape_queue_rw_tail(drive, | 2129 | ssize_t retval = idetape_queue_rw_tail(drive, |
2837 | REQ_IDETAPE_WRITE, 0, | 2130 | REQ_IDETAPE_WRITE, 0, |
2838 | tape->merge_stage->bh); | 2131 | tape->merge_bh); |
2839 | if (retval < 0) { | 2132 | if (retval < 0) { |
2840 | __idetape_kfree_stage(tape->merge_stage); | 2133 | ide_tape_kfree_buffer(tape); |
2841 | tape->merge_stage = NULL; | 2134 | tape->merge_bh = NULL; |
2842 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 2135 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
2843 | return retval; | 2136 | return retval; |
2844 | } | 2137 | } |
@@ -2846,49 +2139,44 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, | |||
2846 | } | 2139 | } |
2847 | if (count == 0) | 2140 | if (count == 0) |
2848 | return (0); | 2141 | return (0); |
2849 | if (tape->restart_speed_control_req) | 2142 | if (tape->merge_bh_size) { |
2850 | idetape_restart_speed_control(drive); | 2143 | if (tape->merge_bh_size >= tape->buffer_size) { |
2851 | if (tape->merge_stage_size) { | ||
2852 | if (tape->merge_stage_size >= tape->stage_size) { | ||
2853 | printk(KERN_ERR "ide-tape: bug: merge buf too big\n"); | 2144 | printk(KERN_ERR "ide-tape: bug: merge buf too big\n"); |
2854 | tape->merge_stage_size = 0; | 2145 | tape->merge_bh_size = 0; |
2855 | } | 2146 | } |
2856 | actually_written = min((unsigned int) | 2147 | actually_written = min((unsigned int) |
2857 | (tape->stage_size - tape->merge_stage_size), | 2148 | (tape->buffer_size - tape->merge_bh_size), |
2858 | (unsigned int)count); | 2149 | (unsigned int)count); |
2859 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, | 2150 | if (idetape_copy_stage_from_user(tape, buf, actually_written)) |
2860 | actually_written)) | ||
2861 | ret = -EFAULT; | 2151 | ret = -EFAULT; |
2862 | buf += actually_written; | 2152 | buf += actually_written; |
2863 | tape->merge_stage_size += actually_written; | 2153 | tape->merge_bh_size += actually_written; |
2864 | count -= actually_written; | 2154 | count -= actually_written; |
2865 | 2155 | ||
2866 | if (tape->merge_stage_size == tape->stage_size) { | 2156 | if (tape->merge_bh_size == tape->buffer_size) { |
2867 | ssize_t retval; | 2157 | ssize_t retval; |
2868 | tape->merge_stage_size = 0; | 2158 | tape->merge_bh_size = 0; |
2869 | retval = idetape_add_chrdev_write_request(drive, ctl); | 2159 | retval = idetape_add_chrdev_write_request(drive, ctl); |
2870 | if (retval <= 0) | 2160 | if (retval <= 0) |
2871 | return (retval); | 2161 | return (retval); |
2872 | } | 2162 | } |
2873 | } | 2163 | } |
2874 | while (count >= tape->stage_size) { | 2164 | while (count >= tape->buffer_size) { |
2875 | ssize_t retval; | 2165 | ssize_t retval; |
2876 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, | 2166 | if (idetape_copy_stage_from_user(tape, buf, tape->buffer_size)) |
2877 | tape->stage_size)) | ||
2878 | ret = -EFAULT; | 2167 | ret = -EFAULT; |
2879 | buf += tape->stage_size; | 2168 | buf += tape->buffer_size; |
2880 | count -= tape->stage_size; | 2169 | count -= tape->buffer_size; |
2881 | retval = idetape_add_chrdev_write_request(drive, ctl); | 2170 | retval = idetape_add_chrdev_write_request(drive, ctl); |
2882 | actually_written += tape->stage_size; | 2171 | actually_written += tape->buffer_size; |
2883 | if (retval <= 0) | 2172 | if (retval <= 0) |
2884 | return (retval); | 2173 | return (retval); |
2885 | } | 2174 | } |
2886 | if (count) { | 2175 | if (count) { |
2887 | actually_written += count; | 2176 | actually_written += count; |
2888 | if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, | 2177 | if (idetape_copy_stage_from_user(tape, buf, count)) |
2889 | count)) | ||
2890 | ret = -EFAULT; | 2178 | ret = -EFAULT; |
2891 | tape->merge_stage_size += count; | 2179 | tape->merge_bh_size += count; |
2892 | } | 2180 | } |
2893 | return ret ? ret : actually_written; | 2181 | return ret ? ret : actually_written; |
2894 | } | 2182 | } |
@@ -2912,8 +2200,7 @@ static int idetape_write_filemark(ide_drive_t *drive) | |||
2912 | * | 2200 | * |
2913 | * Note: MTBSF and MTBSFM are not supported when the tape doesn't support | 2201 | * Note: MTBSF and MTBSFM are not supported when the tape doesn't support |
2914 | * spacing over filemarks in the reverse direction. In this case, MTFSFM is also | 2202 | * spacing over filemarks in the reverse direction. In this case, MTFSFM is also |
2915 | * usually not supported (it is supported in the rare case in which we crossed | 2203 | * usually not supported. |
2916 | * the filemark during our read-ahead pipelined operation mode). | ||
2917 | * | 2204 | * |
2918 | * The following commands are currently not supported: | 2205 | * The following commands are currently not supported: |
2919 | * | 2206 | * |
@@ -2929,7 +2216,6 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
2929 | debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", | 2216 | debug_log(DBG_ERR, "Handling MTIOCTOP ioctl: mt_op=%d, mt_count=%d\n", |
2930 | mt_op, mt_count); | 2217 | mt_op, mt_count); |
2931 | 2218 | ||
2932 | /* Commands which need our pipelined read-ahead stages. */ | ||
2933 | switch (mt_op) { | 2219 | switch (mt_op) { |
2934 | case MTFSF: | 2220 | case MTFSF: |
2935 | case MTFSFM: | 2221 | case MTFSFM: |
@@ -2946,7 +2232,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
2946 | case MTWEOF: | 2232 | case MTWEOF: |
2947 | if (tape->write_prot) | 2233 | if (tape->write_prot) |
2948 | return -EACCES; | 2234 | return -EACCES; |
2949 | idetape_discard_read_pipeline(drive, 1); | 2235 | ide_tape_discard_merge_buffer(drive, 1); |
2950 | for (i = 0; i < mt_count; i++) { | 2236 | for (i = 0; i < mt_count; i++) { |
2951 | retval = idetape_write_filemark(drive); | 2237 | retval = idetape_write_filemark(drive); |
2952 | if (retval) | 2238 | if (retval) |
@@ -2954,12 +2240,12 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
2954 | } | 2240 | } |
2955 | return 0; | 2241 | return 0; |
2956 | case MTREW: | 2242 | case MTREW: |
2957 | idetape_discard_read_pipeline(drive, 0); | 2243 | ide_tape_discard_merge_buffer(drive, 0); |
2958 | if (idetape_rewind_tape(drive)) | 2244 | if (idetape_rewind_tape(drive)) |
2959 | return -EIO; | 2245 | return -EIO; |
2960 | return 0; | 2246 | return 0; |
2961 | case MTLOAD: | 2247 | case MTLOAD: |
2962 | idetape_discard_read_pipeline(drive, 0); | 2248 | ide_tape_discard_merge_buffer(drive, 0); |
2963 | idetape_create_load_unload_cmd(drive, &pc, | 2249 | idetape_create_load_unload_cmd(drive, &pc, |
2964 | IDETAPE_LU_LOAD_MASK); | 2250 | IDETAPE_LU_LOAD_MASK); |
2965 | return idetape_queue_pc_tail(drive, &pc); | 2251 | return idetape_queue_pc_tail(drive, &pc); |
@@ -2974,7 +2260,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
2974 | if (!idetape_queue_pc_tail(drive, &pc)) | 2260 | if (!idetape_queue_pc_tail(drive, &pc)) |
2975 | tape->door_locked = DOOR_UNLOCKED; | 2261 | tape->door_locked = DOOR_UNLOCKED; |
2976 | } | 2262 | } |
2977 | idetape_discard_read_pipeline(drive, 0); | 2263 | ide_tape_discard_merge_buffer(drive, 0); |
2978 | idetape_create_load_unload_cmd(drive, &pc, | 2264 | idetape_create_load_unload_cmd(drive, &pc, |
2979 | !IDETAPE_LU_LOAD_MASK); | 2265 | !IDETAPE_LU_LOAD_MASK); |
2980 | retval = idetape_queue_pc_tail(drive, &pc); | 2266 | retval = idetape_queue_pc_tail(drive, &pc); |
@@ -2982,10 +2268,10 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
2982 | clear_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); | 2268 | clear_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags); |
2983 | return retval; | 2269 | return retval; |
2984 | case MTNOP: | 2270 | case MTNOP: |
2985 | idetape_discard_read_pipeline(drive, 0); | 2271 | ide_tape_discard_merge_buffer(drive, 0); |
2986 | return idetape_flush_tape_buffers(drive); | 2272 | return idetape_flush_tape_buffers(drive); |
2987 | case MTRETEN: | 2273 | case MTRETEN: |
2988 | idetape_discard_read_pipeline(drive, 0); | 2274 | ide_tape_discard_merge_buffer(drive, 0); |
2989 | idetape_create_load_unload_cmd(drive, &pc, | 2275 | idetape_create_load_unload_cmd(drive, &pc, |
2990 | IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); | 2276 | IDETAPE_LU_RETENSION_MASK | IDETAPE_LU_LOAD_MASK); |
2991 | return idetape_queue_pc_tail(drive, &pc); | 2277 | return idetape_queue_pc_tail(drive, &pc); |
@@ -3007,11 +2293,11 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count) | |||
3007 | set_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); | 2293 | set_bit(IDETAPE_FLAG_DETECT_BS, &tape->flags); |
3008 | return 0; | 2294 | return 0; |
3009 | case MTSEEK: | 2295 | case MTSEEK: |
3010 | idetape_discard_read_pipeline(drive, 0); | 2296 | ide_tape_discard_merge_buffer(drive, 0); |
3011 | return idetape_position_tape(drive, | 2297 | return idetape_position_tape(drive, |
3012 | mt_count * tape->user_bs_factor, tape->partition, 0); | 2298 | mt_count * tape->user_bs_factor, tape->partition, 0); |
3013 | case MTSETPART: | 2299 | case MTSETPART: |
3014 | idetape_discard_read_pipeline(drive, 0); | 2300 | ide_tape_discard_merge_buffer(drive, 0); |
3015 | return idetape_position_tape(drive, 0, mt_count, 0); | 2301 | return idetape_position_tape(drive, 0, mt_count, 0); |
3016 | case MTFSR: | 2302 | case MTFSR: |
3017 | case MTBSR: | 2303 | case MTBSR: |
@@ -3056,13 +2342,12 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, | |||
3056 | 2342 | ||
3057 | debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd); | 2343 | debug_log(DBG_CHRDEV, "Enter %s, cmd=%u\n", __func__, cmd); |
3058 | 2344 | ||
3059 | tape->restart_speed_control_req = 1; | ||
3060 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { | 2345 | if (tape->chrdev_dir == IDETAPE_DIR_WRITE) { |
3061 | idetape_empty_write_pipeline(drive); | 2346 | ide_tape_flush_merge_buffer(drive); |
3062 | idetape_flush_tape_buffers(drive); | 2347 | idetape_flush_tape_buffers(drive); |
3063 | } | 2348 | } |
3064 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { | 2349 | if (cmd == MTIOCGET || cmd == MTIOCPOS) { |
3065 | block_offset = idetape_pipeline_size(drive) / | 2350 | block_offset = tape->merge_bh_size / |
3066 | (tape->blk_size * tape->user_bs_factor); | 2351 | (tape->blk_size * tape->user_bs_factor); |
3067 | position = idetape_read_position(drive); | 2352 | position = idetape_read_position(drive); |
3068 | if (position < 0) | 2353 | if (position < 0) |
@@ -3094,7 +2379,7 @@ static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, | |||
3094 | return 0; | 2379 | return 0; |
3095 | default: | 2380 | default: |
3096 | if (tape->chrdev_dir == IDETAPE_DIR_READ) | 2381 | if (tape->chrdev_dir == IDETAPE_DIR_READ) |
3097 | idetape_discard_read_pipeline(drive, 1); | 2382 | ide_tape_discard_merge_buffer(drive, 1); |
3098 | return idetape_blkdev_ioctl(drive, cmd, arg); | 2383 | return idetape_blkdev_ioctl(drive, cmd, arg); |
3099 | } | 2384 | } |
3100 | } | 2385 | } |
@@ -3168,9 +2453,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp) | |||
3168 | if (!test_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags)) | 2453 | if (!test_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags)) |
3169 | (void)idetape_rewind_tape(drive); | 2454 | (void)idetape_rewind_tape(drive); |
3170 | 2455 | ||
3171 | if (tape->chrdev_dir != IDETAPE_DIR_READ) | ||
3172 | clear_bit(IDETAPE_FLAG_PIPELINE_ERR, &tape->flags); | ||
3173 | |||
3174 | /* Read block size and write protect status from drive. */ | 2456 | /* Read block size and write protect status from drive. */ |
3175 | ide_tape_get_bsize_from_bdesc(drive); | 2457 | ide_tape_get_bsize_from_bdesc(drive); |
3176 | 2458 | ||
@@ -3199,8 +2481,6 @@ static int idetape_chrdev_open(struct inode *inode, struct file *filp) | |||
3199 | } | 2481 | } |
3200 | } | 2482 | } |
3201 | } | 2483 | } |
3202 | idetape_restart_speed_control(drive); | ||
3203 | tape->restart_speed_control_req = 0; | ||
3204 | return 0; | 2484 | return 0; |
3205 | 2485 | ||
3206 | out_put_tape: | 2486 | out_put_tape: |
@@ -3212,13 +2492,13 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor) | |||
3212 | { | 2492 | { |
3213 | idetape_tape_t *tape = drive->driver_data; | 2493 | idetape_tape_t *tape = drive->driver_data; |
3214 | 2494 | ||
3215 | idetape_empty_write_pipeline(drive); | 2495 | ide_tape_flush_merge_buffer(drive); |
3216 | tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0); | 2496 | tape->merge_bh = ide_tape_kmalloc_buffer(tape, 1, 0); |
3217 | if (tape->merge_stage != NULL) { | 2497 | if (tape->merge_bh != NULL) { |
3218 | idetape_pad_zeros(drive, tape->blk_size * | 2498 | idetape_pad_zeros(drive, tape->blk_size * |
3219 | (tape->user_bs_factor - 1)); | 2499 | (tape->user_bs_factor - 1)); |
3220 | __idetape_kfree_stage(tape->merge_stage); | 2500 | ide_tape_kfree_buffer(tape); |
3221 | tape->merge_stage = NULL; | 2501 | tape->merge_bh = NULL; |
3222 | } | 2502 | } |
3223 | idetape_write_filemark(drive); | 2503 | idetape_write_filemark(drive); |
3224 | idetape_flush_tape_buffers(drive); | 2504 | idetape_flush_tape_buffers(drive); |
@@ -3241,14 +2521,9 @@ static int idetape_chrdev_release(struct inode *inode, struct file *filp) | |||
3241 | idetape_write_release(drive, minor); | 2521 | idetape_write_release(drive, minor); |
3242 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { | 2522 | if (tape->chrdev_dir == IDETAPE_DIR_READ) { |
3243 | if (minor < 128) | 2523 | if (minor < 128) |
3244 | idetape_discard_read_pipeline(drive, 1); | 2524 | ide_tape_discard_merge_buffer(drive, 1); |
3245 | else | ||
3246 | idetape_wait_for_pipeline(drive); | ||
3247 | } | ||
3248 | if (tape->cache_stage != NULL) { | ||
3249 | __idetape_kfree_stage(tape->cache_stage); | ||
3250 | tape->cache_stage = NULL; | ||
3251 | } | 2525 | } |
2526 | |||
3252 | if (minor < 128 && test_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags)) | 2527 | if (minor < 128 && test_bit(IDETAPE_FLAG_MEDIUM_PRESENT, &tape->flags)) |
3253 | (void) idetape_rewind_tape(drive); | 2528 | (void) idetape_rewind_tape(drive); |
3254 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { | 2529 | if (tape->chrdev_dir == IDETAPE_DIR_NONE) { |
@@ -3385,33 +2660,15 @@ static void idetape_add_settings(ide_drive_t *drive) | |||
3385 | 2660 | ||
3386 | ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, | 2661 | ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, |
3387 | 1, 2, (u16 *)&tape->caps[16], NULL); | 2662 | 1, 2, (u16 *)&tape->caps[16], NULL); |
3388 | ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, | ||
3389 | tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); | ||
3390 | ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, | ||
3391 | tape->stage_size / 1024, 1, &tape->max_stages, NULL); | ||
3392 | ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, | ||
3393 | tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); | ||
3394 | ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, | ||
3395 | 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, | ||
3396 | NULL); | ||
3397 | ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, | ||
3398 | 0xffff, tape->stage_size / 1024, 1, | ||
3399 | &tape->nr_pending_stages, NULL); | ||
3400 | ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, | 2663 | ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, |
3401 | 1, 1, (u16 *)&tape->caps[14], NULL); | 2664 | 1, 1, (u16 *)&tape->caps[14], NULL); |
3402 | ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, | 2665 | ide_add_setting(drive, "buffer_size", SETTING_READ, TYPE_INT, 0, 0xffff, |
3403 | 1024, &tape->stage_size, NULL); | 2666 | 1, 1024, &tape->buffer_size, NULL); |
3404 | ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, | 2667 | ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, |
3405 | IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq, | 2668 | IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_freq, |
3406 | NULL); | 2669 | NULL); |
3407 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, | 2670 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, |
3408 | 1, &drive->dsc_overlap, NULL); | 2671 | 1, &drive->dsc_overlap, NULL); |
3409 | ide_add_setting(drive, "pipeline_head_speed_c", SETTING_READ, TYPE_INT, | ||
3410 | 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, | ||
3411 | NULL); | ||
3412 | ide_add_setting(drive, "pipeline_head_speed_u", SETTING_READ, TYPE_INT, | ||
3413 | 0, 0xffff, 1, 1, | ||
3414 | &tape->uncontrolled_pipeline_head_speed, NULL); | ||
3415 | ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, | 2672 | ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, |
3416 | 1, 1, &tape->avg_speed, NULL); | 2673 | 1, 1, &tape->avg_speed, NULL); |
3417 | ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1, | 2674 | ide_add_setting(drive, "debug_mask", SETTING_RW, TYPE_INT, 0, 0xffff, 1, |
@@ -3434,11 +2691,10 @@ static inline void idetape_add_settings(ide_drive_t *drive) { ; } | |||
3434 | */ | 2691 | */ |
3435 | static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) | 2692 | static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) |
3436 | { | 2693 | { |
3437 | unsigned long t1, tmid, tn, t; | 2694 | unsigned long t; |
3438 | int speed; | 2695 | int speed; |
3439 | int stage_size; | 2696 | int buffer_size; |
3440 | u8 gcw[2]; | 2697 | u8 gcw[2]; |
3441 | struct sysinfo si; | ||
3442 | u16 *ctl = (u16 *)&tape->caps[12]; | 2698 | u16 *ctl = (u16 *)&tape->caps[12]; |
3443 | 2699 | ||
3444 | spin_lock_init(&tape->lock); | 2700 | spin_lock_init(&tape->lock); |
@@ -3457,65 +2713,33 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) | |||
3457 | tape->name[2] = '0' + minor; | 2713 | tape->name[2] = '0' + minor; |
3458 | tape->chrdev_dir = IDETAPE_DIR_NONE; | 2714 | tape->chrdev_dir = IDETAPE_DIR_NONE; |
3459 | tape->pc = tape->pc_stack; | 2715 | tape->pc = tape->pc_stack; |
3460 | tape->max_insert_speed = 10000; | ||
3461 | tape->speed_control = 1; | ||
3462 | *((unsigned short *) &gcw) = drive->id->config; | 2716 | *((unsigned short *) &gcw) = drive->id->config; |
3463 | 2717 | ||
3464 | /* Command packet DRQ type */ | 2718 | /* Command packet DRQ type */ |
3465 | if (((gcw[0] & 0x60) >> 5) == 1) | 2719 | if (((gcw[0] & 0x60) >> 5) == 1) |
3466 | set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags); | 2720 | set_bit(IDETAPE_FLAG_DRQ_INTERRUPT, &tape->flags); |
3467 | 2721 | ||
3468 | tape->min_pipeline = 10; | ||
3469 | tape->max_pipeline = 10; | ||
3470 | tape->max_stages = 10; | ||
3471 | |||
3472 | idetape_get_inquiry_results(drive); | 2722 | idetape_get_inquiry_results(drive); |
3473 | idetape_get_mode_sense_results(drive); | 2723 | idetape_get_mode_sense_results(drive); |
3474 | ide_tape_get_bsize_from_bdesc(drive); | 2724 | ide_tape_get_bsize_from_bdesc(drive); |
3475 | tape->user_bs_factor = 1; | 2725 | tape->user_bs_factor = 1; |
3476 | tape->stage_size = *ctl * tape->blk_size; | 2726 | tape->buffer_size = *ctl * tape->blk_size; |
3477 | while (tape->stage_size > 0xffff) { | 2727 | while (tape->buffer_size > 0xffff) { |
3478 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); | 2728 | printk(KERN_NOTICE "ide-tape: decreasing stage size\n"); |
3479 | *ctl /= 2; | 2729 | *ctl /= 2; |
3480 | tape->stage_size = *ctl * tape->blk_size; | 2730 | tape->buffer_size = *ctl * tape->blk_size; |
3481 | } | 2731 | } |
3482 | stage_size = tape->stage_size; | 2732 | buffer_size = tape->buffer_size; |
3483 | tape->pages_per_stage = stage_size / PAGE_SIZE; | 2733 | tape->pages_per_buffer = buffer_size / PAGE_SIZE; |
3484 | if (stage_size % PAGE_SIZE) { | 2734 | if (buffer_size % PAGE_SIZE) { |
3485 | tape->pages_per_stage++; | 2735 | tape->pages_per_buffer++; |
3486 | tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE; | 2736 | tape->excess_bh_size = PAGE_SIZE - buffer_size % PAGE_SIZE; |
3487 | } | 2737 | } |
3488 | 2738 | ||
3489 | /* Select the "best" DSC read/write polling freq and pipeline size. */ | 2739 | /* select the "best" DSC read/write polling freq */ |
3490 | speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); | 2740 | speed = max(*(u16 *)&tape->caps[14], *(u16 *)&tape->caps[8]); |
3491 | 2741 | ||
3492 | tape->max_stages = speed * 1000 * 10 / tape->stage_size; | 2742 | t = (IDETAPE_FIFO_THRESHOLD * tape->buffer_size * HZ) / (speed * 1000); |
3493 | |||
3494 | /* Limit memory use for pipeline to 10% of physical memory */ | ||
3495 | si_meminfo(&si); | ||
3496 | if (tape->max_stages * tape->stage_size > | ||
3497 | si.totalram * si.mem_unit / 10) | ||
3498 | tape->max_stages = | ||
3499 | si.totalram * si.mem_unit / (10 * tape->stage_size); | ||
3500 | |||
3501 | tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES); | ||
3502 | tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES); | ||
3503 | tape->max_pipeline = | ||
3504 | min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES); | ||
3505 | if (tape->max_stages == 0) { | ||
3506 | tape->max_stages = 1; | ||
3507 | tape->min_pipeline = 1; | ||
3508 | tape->max_pipeline = 1; | ||
3509 | } | ||
3510 | |||
3511 | t1 = (tape->stage_size * HZ) / (speed * 1000); | ||
3512 | tmid = (*(u16 *)&tape->caps[16] * 32 * HZ) / (speed * 125); | ||
3513 | tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000); | ||
3514 | |||
3515 | if (tape->max_stages) | ||
3516 | t = tn; | ||
3517 | else | ||
3518 | t = t1; | ||
3519 | 2743 | ||
3520 | /* | 2744 | /* |
3521 | * Ensure that the number we got makes sense; limit it within | 2745 | * Ensure that the number we got makes sense; limit it within |
@@ -3525,11 +2749,10 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor) | |||
3525 | min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), | 2749 | min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), |
3526 | IDETAPE_DSC_RW_MIN); | 2750 | IDETAPE_DSC_RW_MIN); |
3527 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " | 2751 | printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, " |
3528 | "%dkB pipeline, %lums tDSC%s\n", | 2752 | "%lums tDSC%s\n", |
3529 | drive->name, tape->name, *(u16 *)&tape->caps[14], | 2753 | drive->name, tape->name, *(u16 *)&tape->caps[14], |
3530 | (*(u16 *)&tape->caps[16] * 512) / tape->stage_size, | 2754 | (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, |
3531 | tape->stage_size / 1024, | 2755 | tape->buffer_size / 1024, |
3532 | tape->max_stages * tape->stage_size / 1024, | ||
3533 | tape->best_dsc_rw_freq * 1000 / HZ, | 2756 | tape->best_dsc_rw_freq * 1000 / HZ, |
3534 | drive->using_dma ? ", DMA":""); | 2757 | drive->using_dma ? ", DMA":""); |
3535 | 2758 | ||
@@ -3553,7 +2776,7 @@ static void ide_tape_release(struct kref *kref) | |||
3553 | ide_drive_t *drive = tape->drive; | 2776 | ide_drive_t *drive = tape->drive; |
3554 | struct gendisk *g = tape->disk; | 2777 | struct gendisk *g = tape->disk; |
3555 | 2778 | ||
3556 | BUG_ON(tape->first_stage != NULL || tape->merge_stage_size); | 2779 | BUG_ON(tape->merge_bh_size); |
3557 | 2780 | ||
3558 | drive->dsc_overlap = 0; | 2781 | drive->dsc_overlap = 0; |
3559 | drive->driver_data = NULL; | 2782 | drive->driver_data = NULL; |