• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500-V1.0.1.40_1.0.68/src/linux/linux-2.6/drivers/ide/

Lines Matching defs:tape

2  * linux/drivers/ide/ide-tape.c		Version 1.19	Nov, 2003
6 * $Header: /projects/cvsroot/src/linux/linux-2.6/drivers/ide/ide-tape.c,v 1.1.1.1 2007/08/03 18:52:31 rnuti Exp $
29 * with the current tape speed. At this point, the pipeline will get
30 * shorter and shorter but the tape will still be streaming at the same speed.
36 * buffering done by the user program, as ide-tape already provides all the
43 * which seems to be the maximum throughput supported by my tape.
48 * of pipeline stages (each stage is about 26 KB with my tape).
50 * to the user task. In read mode, the actual tape position
72 * reach the optimum value which just manages to keep the tape
78 * In pipelined write mode, ide-tape can not return accurate error codes
87 * For accurate tape positioning and error reporting, disabling
101 * other device while the tape is busy executing a command. The
102 * DSC overlap method involves polling the tape's status register
103 * for the DSC bit, and servicing the other device while the tape
107 * it is recommended that new tape drives will *in addition*
191 * keep the tape constantly streaming. To accomplish that, we implement
200 * cannot be disabled (calculate_speeds() divides by tape->max_stages.)
259 * tape fifo in which we will start to refill the buffer. Decreasing
270 * important function in ide-tape. There are two cases in which we
274 * can transfer data from/to the tape's data buffers, without
275 * causing an actual media access. In case the tape is not
294 * tape operation.
327 * For general magnetic tape device compatibility.
562 /* Copy of the tape's Capabilities and Mechanical Page */
568 * At most, there is only one ide-tape originated data transfer
575 * The data buffer size is chosen based on the tape's
580 /* Data buffer size (chosen based on the tape's recommendation */
616 /* protects the ide-tape queue */
620 * Measures average tape speed
636 /* the tape hardware is write protected */
638 /* the tape is write protected (hardware or opened as read-only) */
653 * 2. written/read to/from the tape buffers (idetape_bh).
654 * 3. written/read by the tape to/from the media (tape_head).
662 * Speed control at the tape buffers input/output
671 * Measure tape still time, in milliseconds
718 struct ide_tape_obj *tape = NULL;
721 tape = ide_tape_g(disk);
722 if (tape)
723 kref_get(&tape->kref);
725 return tape;
730 static void ide_tape_put(struct ide_tape_obj *tape)
733 kref_put(&tape->kref, ide_tape_release);
748 #define IDETAPE_ADDRESS_VALID 1 /* 0 When the tape position is unknown */
756 /* 0 = no tape is loaded, so we don't rewind after ejecting */
760 * Supported ATAPI tape drives packet commands
882 * by ide-tape.
969 struct ide_tape_obj *tape = NULL;
972 tape = idetape_devs[i];
973 if (tape)
974 kref_get(&tape->kref);
976 return tape;
1004 printk(KERN_ERR "ide-tape: bh == NULL in "
1031 printk(KERN_ERR "ide-tape: bh == NULL in "
1062 printk(KERN_ERR "ide-tape: bh == NULL in "
1084 idetape_tape_t *tape = drive->driver_data;
1087 if (tape->debug_level >= 5)
1088 printk(KERN_INFO "ide-tape: pc_stack_index=%d\n",
1089 tape->pc_stack_index);
1091 if (tape->pc_stack_index == IDETAPE_PC_STACK)
1092 tape->pc_stack_index=0;
1093 return (&tape->pc_stack[tape->pc_stack_index++]);
1111 idetape_tape_t *tape = drive->driver_data;
1114 if (tape->debug_level >= 5)
1115 printk(KERN_INFO "ide-tape: rq_stack_index=%d\n",
1116 tape->rq_stack_index);
1118 if (tape->rq_stack_index == IDETAPE_PC_STACK)
1119 tape->rq_stack_index=0;
1120 return (&tape->rq_stack[tape->rq_stack_index++]);
1145 idetape_tape_t *tape = drive->driver_data;
1146 idetape_pc_t *pc = tape->failed_pc;
1148 tape->sense = *result;
1149 tape->sense_key = result->sense_key;
1150 tape->asc = result->asc;
1151 tape->ascq = result->ascq;
1157 if (tape->debug_level >= 1)
1158 printk(KERN_INFO "ide-tape: pc = %x, sense key = %x, "
1165 * Correct pc->actually_transferred by asking the tape.
1168 pc->actually_transferred = pc->request_transfer - tape->tape_block_size * ntohl(get_unaligned(&result->information));
1214 idetape_tape_t *tape = drive->driver_data;
1215 idetape_stage_t *stage = tape->next_stage;
1219 if (tape->debug_level >= 4)
1220 printk(KERN_INFO "ide-tape: Reached idetape_active_next_stage\n");
1224 printk(KERN_ERR "ide-tape: bug: Trying to activate a non existing stage\n");
1229 rq->rq_disk = tape->disk;
1232 tape->active_data_request = rq;
1233 tape->active_stage = stage;
1234 tape->next_stage = stage->next;
1246 idetape_tape_t *tape = drive->driver_data;
1247 int increase = (tape->max_pipeline - tape->min_pipeline) / 10;
1250 if (tape->debug_level >= 4)
1251 printk (KERN_INFO "ide-tape: Reached idetape_increase_max_pipeline_stages\n");
1254 tape->max_stages += max(increase, 1);
1255 tape->max_stages = max(tape->max_stages, tape->min_pipeline);
1256 tape->max_stages = min(tape->max_stages, tape->max_pipeline);
1284 static void idetape_kfree_stage (idetape_tape_t *tape, idetape_stage_t *stage)
1290 * idetape_remove_stage_head removes tape->first_stage from the pipeline.
1295 idetape_tape_t *tape = drive->driver_data;
1299 if (tape->debug_level >= 4)
1300 printk(KERN_INFO "ide-tape: Reached idetape_remove_stage_head\n");
1303 if (tape->first_stage == NULL) {
1304 printk(KERN_ERR "ide-tape: bug: tape->first_stage is NULL\n");
1307 if (tape->active_stage == tape->first_stage) {
1308 printk(KERN_ERR "ide-tape: bug: Trying to free our active pipeline stage\n");
1312 stage = tape->first_stage;
1313 tape->first_stage = stage->next;
1314 idetape_kfree_stage(tape, stage);
1315 tape->nr_stages--;
1316 if (tape->first_stage == NULL) {
1317 tape->last_stage = NULL;
1319 if (tape->next_stage != NULL)
1320 printk(KERN_ERR "ide-tape: bug: tape->next_stage != NULL\n");
1321 if (tape->nr_stages)
1322 printk(KERN_ERR "ide-tape: bug: nr_stages should be 0 now\n");
1329 * to the end of the list, and point tape->last_stage to new_last_stage.
1334 idetape_tape_t *tape = drive->driver_data;
1339 if (tape->debug_level >= 4)
1340 printk(KERN_INFO "ide-tape: %s: idetape_abort_pipeline called\n", tape->name);
1344 idetape_kfree_stage(tape, stage);
1345 --tape->nr_stages;
1346 --tape->nr_pending_stages;
1351 tape->last_stage = new_last_stage;
1352 tape->next_stage = NULL;
1362 idetape_tape_t *tape = drive->driver_data;
1369 if (tape->debug_level >= 4)
1370 printk(KERN_INFO "ide-tape: Reached idetape_end_request\n");
1380 tape->failed_pc = NULL;
1382 spin_lock_irqsave(&tape->spinlock, flags);
1385 if (tape->active_data_request == rq) {
1386 active_stage = tape->active_stage;
1387 tape->active_stage = NULL;
1388 tape->active_data_request = NULL;
1389 tape->nr_pending_stages--;
1393 set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
1399 set_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
1403 if (tape->next_stage != NULL) {
1409 (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end);
1421 if (tape->active_data_request == NULL)
1422 clear_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
1423 spin_unlock_irqrestore(&tape->spinlock, flags);
1429 idetape_tape_t *tape = drive->driver_data;
1432 if (tape->debug_level >= 4)
1433 printk(KERN_INFO "ide-tape: Reached idetape_request_sense_callback\n");
1435 if (!tape->pc->error) {
1436 idetape_analyze_error(drive, (idetape_request_sense_result_t *) tape->pc->buffer);
1439 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - Aborting request!\n");
1482 struct ide_tape_obj *tape = drive->driver_data;
1486 rq->rq_disk = tape->disk;
1497 idetape_tape_t *tape = drive->driver_data;
1506 set_bit(IDETAPE_IGNORE_DSC, &tape->flags);
1518 idetape_tape_t *tape = drive->driver_data;
1521 if (tape->debug_level >= 4)
1522 printk(KERN_INFO "ide-tape: idetape_postpone_request\n");
1524 tape->postponed_rq = HWGROUP(drive)->rq;
1525 ide_stall_queue(drive, tape->dsc_polling_frequency);
1539 idetape_tape_t *tape = drive->driver_data;
1543 idetape_pc_t *pc = tape->pc;
1551 if (tape->debug_level >= 4)
1552 printk(KERN_INFO "ide-tape: Reached idetape_pc_intr "
1563 * if the tape is crossing a filemark during a
1567 * error). In that case, we will later ask the tape
1576 * If the tape crosses a filemark during a READ
1588 if (tape->debug_level >= 4)
1589 printk(KERN_INFO "ide-tape: DMA finished\n");
1596 if (tape->debug_level >= 2)
1597 printk(KERN_INFO "ide-tape: Packet command completed, %d bytes transferred\n", pc->actually_transferred);
1607 printk(KERN_INFO "ide-tape: %s: simulating error\n",
1608 tape->name);
1616 if (tape->debug_level >= 1)
1617 printk(KERN_INFO "ide-tape: %s: I/O error\n",
1618 tape->name);
1621 printk(KERN_ERR "ide-tape: I/O error in request sense command\n");
1625 if (tape->debug_level >= 1)
1626 printk(KERN_INFO "ide-tape: [cmd %x]: check condition\n", pc->c[0]);
1635 tape->dsc_polling_start = jiffies;
1636 tape->dsc_polling_frequency = IDETAPE_DSC_MA_FAST;
1637 tape->dsc_timeout = jiffies + IDETAPE_DSC_MA_TIMEOUT;
1642 if (tape->failed_pc == pc)
1643 tape->failed_pc = NULL;
1648 printk(KERN_ERR "ide-tape: The tape wants to issue more "
1650 printk(KERN_ERR "ide-tape: DMA disabled, reverting to PIO\n");
1661 printk(KERN_ERR "ide-tape: CoD != 0 in idetape_pc_intr\n");
1666 printk(KERN_ERR "ide-tape: We wanted to %s, ",
1668 printk(KERN_ERR "ide-tape: but the tape wants us to %s !\n",
1677 printk(KERN_ERR "ide-tape: The tape wants to send us more data than expected - discarding data\n");
1683 if (tape->debug_level >= 2)
1684 printk(KERN_NOTICE "ide-tape: The tape wants to send us more data than expected - allowing transfer\n");
1705 if (tape->debug_level >= 2)
1706 printk(KERN_INFO "ide-tape: [cmd %x] transferred %d bytes on that interrupt\n", pc->c[0], bcount.all);
1716 * The current Packet Command is available in tape->pc, and will not
1734 * Since the tape drive will not issue an interrupt, we have to
1758 idetape_tape_t *tape = drive->driver_data;
1759 idetape_pc_t *pc = tape->pc;
1765 printk(KERN_ERR "ide-tape: Strange, packet command initiated yet DRQ isn't asserted\n");
1770 printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while issuing "
1775 printk(KERN_ERR "ide-tape: (IO,CoD != (0,1) while "
1782 printk(KERN_ERR "ide-tape: (IO,CoD) != (0,1) while issuing "
1801 idetape_tape_t *tape = drive->driver_data;
1806 if (tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD &&
1808 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
1813 if (tape->failed_pc == NULL && pc->c[0] != IDETAPE_REQUEST_SENSE_CMD)
1814 tape->failed_pc = pc;
1816 tape->pc = pc;
1827 tape->sense_key == 2 && tape->asc == 4 &&
1828 (tape->ascq == 1 || tape->ascq == 8))) {
1829 printk(KERN_ERR "ide-tape: %s: I/O error, "
1832 tape->name, pc->c[0],
1833 tape->sense_key, tape->asc,
1834 tape->ascq);
1839 tape->failed_pc = NULL;
1843 if (tape->debug_level >= 2)
1844 printk(KERN_INFO "ide-tape: Retry number - %d, cmd = %02X\n", pc->retries, pc->c[0]);
1855 printk(KERN_WARNING "ide-tape: DMA disabled, "
1870 if (test_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags)) {
1885 idetape_tape_t *tape = drive->driver_data;
1888 if (tape->debug_level >= 4)
1889 printk(KERN_INFO "ide-tape: Reached idetape_pc_callback\n");
1892 idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
1897 * A mode sense command is used to "sense" tape parameters.
1926 idetape_tape_t *tape = drive->driver_data;
1929 if (time_after(jiffies, tape->controlled_pipeline_head_time + 120 * HZ)) {
1930 tape->controlled_previous_pipeline_head = tape->controlled_last_pipeline_head;
1931 tape->controlled_previous_head_time = tape->controlled_pipeline_head_time;
1932 tape->controlled_last_pipeline_head = tape->pipeline_head;
1933 tape->controlled_pipeline_head_time = jiffies;
1935 if (time_after(jiffies, tape->controlled_pipeline_head_time + 60 * HZ))
1936 tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_last_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_pipeline_head_time);
1937 else if (time_after(jiffies, tape->controlled_previous_head_time))
1938 tape->controlled_pipeline_head_speed = (tape->pipeline_head - tape->controlled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->controlled_previous_head_time);
1940 if (tape->nr_pending_stages < tape->max_stages /*- 1 */) {
1942 if (time_after(jiffies, tape->uncontrolled_previous_head_time + 10 * HZ)) {
1943 tape->uncontrolled_pipeline_head_time = jiffies;
1944 tape->uncontrolled_pipeline_head_speed = (tape->pipeline_head - tape->uncontrolled_previous_pipeline_head) * 32 * HZ / (jiffies - tape->uncontrolled_previous_head_time);
1947 tape->uncontrolled_previous_head_time = jiffies;
1948 tape->uncontrolled_previous_pipeline_head = tape->pipeline_head;
1949 if (time_after(jiffies, tape->uncontrolled_pipeline_head_time + 30 * HZ)) {
1950 tape->uncontrolled_pipeline_head_time = jiffies;
1953 tape->pipeline_head_speed = max(tape->uncontrolled_pipeline_head_speed, tape->controlled_pipeline_head_speed);
1954 if (tape->speed_control == 0) {
1955 tape->max_insert_speed = 5000;
1956 } else if (tape->speed_control == 1) {
1957 if (tape->nr_pending_stages >= tape->max_stages / 2)
1958 tape->max_insert_speed = tape->pipeline_head_speed +
1959 (1100 - tape->pipeline_head_speed) * 2 * (tape->nr_pending_stages - tape->max_stages / 2) / tape->max_stages;
1961 tape->max_insert_speed = 500 +
1962 (tape->pipeline_head_speed - 500) * 2 * tape->nr_pending_stages / tape->max_stages;
1963 if (tape->nr_pending_stages >= tape->max_stages * 99 / 100)
1964 tape->max_insert_speed = 5000;
1965 } else if (tape->speed_control == 2) {
1966 tape->max_insert_speed = tape->pipeline_head_speed * empty / 100 +
1967 (tape->pipeline_head_speed * full / 100 - tape->pipeline_head_speed * empty / 100) * tape->nr_pending_stages / tape->max_stages;
1969 tape->max_insert_speed = tape->speed_control;
1970 tape->max_insert_speed = max(tape->max_insert_speed, 500);
1975 idetape_tape_t *tape = drive->driver_data;
1976 idetape_pc_t *pc = tape->pc;
1984 printk(KERN_ERR "ide-tape: %s: I/O error, ",
1985 tape->name);
1990 if (tape->failed_pc == pc)
1991 tape->failed_pc = NULL;
1994 tape->failed_pc = NULL;
2001 idetape_tape_t *tape = drive->driver_data;
2003 int blocks = tape->pc->actually_transferred / tape->tape_block_size;
2005 tape->avg_size += blocks * tape->tape_block_size;
2006 tape->insert_size += blocks * tape->tape_block_size;
2007 if (tape->insert_size > 1024 * 1024)
2008 tape->measure_insert_time = 1;
2009 if (tape->measure_insert_time) {
2010 tape->measure_insert_time = 0;
2011 tape->insert_time = jiffies;
2012 tape->insert_size = 0;
2014 if (time_after(jiffies, tape->insert_time))
2015 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
2016 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
2017 tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024;
2018 tape->avg_size = 0;
2019 tape->avg_time = jiffies;
2023 if (tape->debug_level >= 4)
2024 printk(KERN_INFO "ide-tape: Reached idetape_rw_callback\n");
2027 tape->first_frame_position += blocks;
2030 if (!tape->pc->error)
2033 idetape_end_request(drive, tape->pc->error, 0);
2037 static void idetape_create_read_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
2047 pc->request_transfer = pc->buffer_size = length * tape->tape_block_size;
2048 if (pc->request_transfer == tape->stage_size)
2052 static void idetape_create_read_buffer_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
2073 static void idetape_create_write_cmd(idetape_tape_t *tape, idetape_pc_t *pc, unsigned int length, struct idetape_bh *bh)
2085 pc->request_transfer = pc->buffer_size = length * tape->tape_block_size;
2086 if (pc->request_transfer == tape->stage_size)
2096 idetape_tape_t *tape = drive->driver_data;
2098 struct request *postponed_rq = tape->postponed_rq;
2102 if (tape->debug_level >= 2)
2103 printk(KERN_INFO "ide-tape: sector: %ld, "
2112 printk(KERN_NOTICE "ide-tape: %s: Unsupported request in "
2121 if (tape->failed_pc != NULL &&
2122 tape->pc->c[0] == IDETAPE_REQUEST_SENSE_CMD) {
2123 return idetape_issue_packet_command(drive, tape->failed_pc);
2128 printk(KERN_ERR "ide-tape: ide-tape.c bug - "
2135 tape->postponed_rq = NULL;
2138 * If the tape is still busy, postpone our request and service
2144 set_bit(IDETAPE_IGNORE_DSC, &tape->flags);
2147 set_bit(IDETAPE_IGNORE_DSC, &tape->flags);
2151 if (tape->tape_still_time > 100 && tape->tape_still_time < 200)
2152 tape->measure_insert_time = 1;
2153 if (time_after(jiffies, tape->insert_time))
2154 tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
2156 if (!test_and_clear_bit(IDETAPE_IGNORE_DSC, &tape->flags) &&
2159 tape->dsc_polling_start = jiffies;
2160 tape->dsc_polling_frequency = tape->best_dsc_rw_frequency;
2161 tape->dsc_timeout = jiffies + IDETAPE_DSC_RW_TIMEOUT;
2162 } else if (time_after(jiffies, tape->dsc_timeout)) {
2163 printk(KERN_ERR "ide-tape: %s: DSC timeout\n",
2164 tape->name);
2171 } else if (time_after(jiffies, tape->dsc_polling_start + IDETAPE_DSC_MA_THRESHOLD))
2172 tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW;
2177 tape->buffer_head++;
2179 IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor);
2181 tape->postpone_cnt = 0;
2183 idetape_create_read_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
2187 tape->buffer_head++;
2189 IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor);
2191 tape->postpone_cnt = 0;
2193 idetape_create_write_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
2197 tape->postpone_cnt = 0;
2199 idetape_create_read_buffer_cmd(tape, pc, rq->current_nr_sectors, (struct idetape_bh *)rq->special);
2220 static inline int idetape_pipeline_active (idetape_tape_t *tape)
2224 rc1 = test_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
2225 rc2 = (tape->active_data_request != NULL);
2232 * a buffer of size tape->stage_size (or a bit more). We attempt to
2241 static idetape_stage_t *__idetape_kmalloc_stage (idetape_tape_t *tape, int full, int clear)
2245 int pages = tape->pages_per_stage;
2292 bh->b_size -= tape->excess_bh_size;
2294 atomic_sub(tape->excess_bh_size, &bh->b_count);
2301 static idetape_stage_t *idetape_kmalloc_stage (idetape_tape_t *tape)
2303 idetape_stage_t *cache_stage = tape->cache_stage;
2306 if (tape->debug_level >= 4)
2307 printk(KERN_INFO "ide-tape: Reached idetape_kmalloc_stage\n");
2310 if (tape->nr_stages >= tape->max_stages)
2313 tape->cache_stage = NULL;
2316 return __idetape_kmalloc_stage(tape, 0, 0);
2319 static int idetape_copy_stage_from_user (idetape_tape_t *tape, idetape_stage_t *stage, const char __user *buf, int n)
2321 struct idetape_bh *bh = tape->bh;
2328 printk(KERN_ERR "ide-tape: bh == NULL in "
2345 tape->bh = bh;
2349 static int idetape_copy_stage_to_user (idetape_tape_t *tape, char __user *buf, idetape_stage_t *stage, int n)
2351 struct idetape_bh *bh = tape->bh;
2358 printk(KERN_ERR "ide-tape: bh == NULL in "
2363 count = min(tape->b_count, n);
2364 if (copy_to_user(buf, tape->b_data, count))
2367 tape->b_data += count;
2368 tape->b_count -= count;
2370 if (!tape->b_count) {
2371 tape->bh = bh = bh->b_reqnext;
2373 tape->b_data = bh->b_data;
2374 tape->b_count = atomic_read(&bh->b_count);
2381 static void idetape_init_merge_stage (idetape_tape_t *tape)
2383 struct idetape_bh *bh = tape->merge_stage->bh;
2385 tape->bh = bh;
2386 if (tape->chrdev_direction == idetape_direction_write)
2389 tape->b_data = bh->b_data;
2390 tape->b_count = atomic_read(&bh->b_count);
2394 static void idetape_switch_buffers (idetape_tape_t *tape, idetape_stage_t *stage)
2399 stage->bh = tape->merge_stage->bh;
2400 tape->merge_stage->bh = tmp;
2401 idetape_init_merge_stage(tape);
2409 idetape_tape_t *tape = drive->driver_data;
2413 if (tape->debug_level >= 4)
2414 printk (KERN_INFO "ide-tape: Reached idetape_add_stage_tail\n");
2416 spin_lock_irqsave(&tape->spinlock, flags);
2418 if (tape->last_stage != NULL)
2419 tape->last_stage->next=stage;
2421 tape->first_stage = tape->next_stage=stage;
2422 tape->last_stage = stage;
2423 if (tape->next_stage == NULL)
2424 tape->next_stage = tape->last_stage;
2425 tape->nr_stages++;
2426 tape->nr_pending_stages++;
2427 spin_unlock_irqrestore(&tape->spinlock, flags);
2440 idetape_tape_t *tape = drive->driver_data;
2444 printk (KERN_ERR "ide-tape: bug: Trying to sleep on non-valid request\n");
2450 spin_unlock_irq(&tape->spinlock);
2453 spin_lock_irq(&tape->spinlock);
2458 idetape_tape_t *tape = drive->driver_data;
2462 if (tape->debug_level >= 4)
2463 printk(KERN_INFO "ide-tape: Reached idetape_read_position_callback\n");
2466 if (!tape->pc->error) {
2467 result = (idetape_read_position_result_t *) tape->pc->buffer;
2469 if (tape->debug_level >= 2)
2470 printk(KERN_INFO "ide-tape: BOP - %s\n",result->bop ? "Yes":"No");
2471 if (tape->debug_level >= 2)
2472 printk(KERN_INFO "ide-tape: EOP - %s\n",result->eop ? "Yes":"No");
2475 printk(KERN_INFO "ide-tape: Block location is unknown to the tape\n");
2476 clear_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
2480 if (tape->debug_level >= 2)
2481 printk(KERN_INFO "ide-tape: Block Location - %u\n", ntohl(result->first_block));
2483 tape->partition = result->partition;
2484 tape->first_frame_position = ntohl(result->first_block);
2485 tape->last_frame_position = ntohl(result->last_block);
2486 tape->blocks_in_buffer = result->blocks_in_buffer[2];
2487 set_bit(IDETAPE_ADDRESS_VALID, &tape->flags);
2542 struct ide_tape_obj *tape = drive->driver_data;
2547 rq.rq_disk = tape->disk;
2562 idetape_tape_t *tape = drive->driver_data;
2567 * Wait for the tape to become ready
2569 set_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
2575 if ((tape->sense_key == 2 && tape->asc == 4 && tape->ascq == 2)
2576 || (tape->asc == 0x3A)) { /* no media */
2583 } else if (!(tape->sense_key == 2 && tape->asc == 4 &&
2584 (tape->ascq == 1 || tape->ascq == 8)))
2618 idetape_tape_t *tape = drive->driver_data;
2623 if (tape->debug_level >= 4)
2624 printk(KERN_INFO "ide-tape: Reached idetape_read_position\n");
2630 position = tape->first_frame_position;
2647 idetape_tape_t *tape = drive->driver_data;
2649 if (!tape->capabilities.lock)
2661 idetape_tape_t *tape = drive->driver_data;
2665 if (tape->chrdev_direction != idetape_direction_read)
2669 cnt = tape->merge_stage_size / tape->tape_block_size;
2670 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
2672 tape->merge_stage_size = 0;
2673 if (tape->merge_stage != NULL) {
2674 __idetape_kfree_stage(tape->merge_stage);
2675 tape->merge_stage = NULL;
2679 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
2680 tape->chrdev_direction = idetape_direction_none;
2683 if (tape->first_stage == NULL)
2686 spin_lock_irqsave(&tape->spinlock, flags);
2687 tape->next_stage = NULL;
2688 if (idetape_pipeline_active(tape))
2689 idetape_wait_for_request(drive, tape->active_data_request);
2690 spin_unlock_irqrestore(&tape->spinlock, flags);
2692 while (tape->first_stage != NULL) {
2693 struct request *rq_ptr = &tape->first_stage->rq;
2700 tape->nr_pending_stages = 0;
2701 tape->max_stages = tape->min_pipeline;
2706 * idetape_position_tape positions the tape to the requested block
2716 idetape_tape_t *tape = drive->driver_data;
2720 if (tape->chrdev_direction == idetape_direction_read)
2734 idetape_tape_t *tape = drive->driver_data;
2743 printk(KERN_INFO "ide-tape: %s: position_tape failed in discard_pipeline()\n", tape->name);
2755 idetape_tape_t *tape = drive->driver_data;
2759 if (tape->debug_level >= 2)
2760 printk(KERN_INFO "ide-tape: idetape_queue_rw_tail: cmd=%d\n",cmd);
2763 if (idetape_pipeline_active(tape)) {
2764 printk(KERN_ERR "ide-tape: bug: the pipeline is active in idetape_queue_rw_tail\n");
2770 rq.rq_disk = tape->disk;
2772 rq.sector = tape->first_frame_position;
2779 if (tape->merge_stage)
2780 idetape_init_merge_stage(tape);
2783 return (tape->tape_block_size * (blocks-rq.current_nr_sectors));
2788 * pipeline stages, starting from tape->next_stage.
2792 idetape_tape_t *tape = drive->driver_data;
2794 if (tape->next_stage == NULL)
2796 if (!idetape_pipeline_active(tape)) {
2797 set_bit(IDETAPE_PIPELINE_ACTIVE, &tape->flags);
2799 (void) ide_do_drive_cmd(drive, tape->active_data_request, ide_end);
2841 idetape_tape_t *tape = drive->driver_data;
2844 if (tape->first_stage == NULL)
2846 spin_lock_irqsave(&tape->spinlock, flags);
2847 if (tape->active_stage == tape->first_stage)
2848 idetape_wait_for_request(drive, tape->active_data_request);
2849 spin_unlock_irqrestore(&tape->spinlock, flags);
2865 idetape_tape_t *tape = drive->driver_data;
2871 if (tape->debug_level >= 3)
2872 printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_write_request\n");
2879 while ((new_stage = idetape_kmalloc_stage(tape)) == NULL) {
2880 spin_lock_irqsave(&tape->spinlock, flags);
2881 if (idetape_pipeline_active(tape)) {
2882 idetape_wait_for_request(drive, tape->active_data_request);
2883 spin_unlock_irqrestore(&tape->spinlock, flags);
2885 spin_unlock_irqrestore(&tape->spinlock, flags);
2887 if (idetape_pipeline_active(tape))
2893 return idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh);
2899 rq->sector = tape->first_frame_position;
2902 idetape_switch_buffers(tape, new_stage);
2904 tape->pipeline_head++;
2906 IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor);
2911 * Estimate whether the tape has stopped writing by checking
2915 * be able to keep up with the higher speeds of the tape.
2917 if (!idetape_pipeline_active(tape)) {
2918 if (tape->nr_stages >= tape->max_stages * 9 / 10 ||
2919 tape->nr_stages >= tape->max_stages - tape->uncontrolled_pipeline_head_speed * 3 * 1024 / tape->tape_block_size) {
2920 tape->measure_insert_time = 1;
2921 tape->insert_time = jiffies;
2922 tape->insert_size = 0;
2923 tape->insert_speed = 0;
2927 if (test_and_clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
2939 idetape_tape_t *tape = drive->driver_data;
2942 while (tape->next_stage || idetape_pipeline_active(tape)) {
2944 spin_lock_irqsave(&tape->spinlock, flags);
2945 if (idetape_pipeline_active(tape))
2946 idetape_wait_for_request(drive, tape->active_data_request);
2947 spin_unlock_irqrestore(&tape->spinlock, flags);
2953 idetape_tape_t *tape = drive->driver_data;
2958 if (tape->chrdev_direction != idetape_direction_write) {
2959 printk(KERN_ERR "ide-tape: bug: Trying to empty write pipeline, but we are not writing.\n");
2962 if (tape->merge_stage_size > tape->stage_size) {
2963 printk(KERN_ERR "ide-tape: bug: merge_buffer too big\n");
2964 tape->merge_stage_size = tape->stage_size;
2967 if (tape->merge_stage_size) {
2968 blocks = tape->merge_stage_size / tape->tape_block_size;
2969 if (tape->merge_stage_size % tape->tape_block_size) {
2973 i = tape->tape_block_size - tape->merge_stage_size % tape->tape_block_size;
2974 bh = tape->bh->b_reqnext;
2979 bh = tape->bh;
2983 printk(KERN_INFO "ide-tape: bug, bh NULL\n");
2994 tape->merge_stage_size = 0;
2997 if (tape->merge_stage != NULL) {
2998 __idetape_kfree_stage(tape->merge_stage);
2999 tape->merge_stage = NULL;
3001 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
3002 tape->chrdev_direction = idetape_direction_none;
3010 tape->max_stages = tape->min_pipeline;
3012 if (tape->first_stage != NULL ||
3013 tape->next_stage != NULL ||
3014 tape->last_stage != NULL ||
3015 tape->nr_stages != 0) {
3016 printk(KERN_ERR "ide-tape: ide-tape pipeline bug, "
3019 tape->first_stage, tape->next_stage,
3020 tape->last_stage, tape->nr_stages);
3027 idetape_tape_t *tape = drive->driver_data;
3029 tape->restart_speed_control_req = 0;
3030 tape->pipeline_head = 0;
3031 tape->controlled_last_pipeline_head = tape->uncontrolled_last_pipeline_head = 0;
3032 tape->controlled_previous_pipeline_head = tape->uncontrolled_previous_pipeline_head = 0;
3033 tape->pipeline_head_speed = tape->controlled_pipeline_head_speed = 5000;
3034 tape->uncontrolled_pipeline_head_speed = 0;
3035 tape->controlled_pipeline_head_time = tape->uncontrolled_pipeline_head_time = jiffies;
3036 tape->controlled_previous_head_time = tape->uncontrolled_previous_head_time = jiffies;
3041 idetape_tape_t *tape = drive->driver_data;
3045 int blocks = tape->capabilities.ctl;
3048 if (tape->chrdev_direction != idetape_direction_read) {
3049 if (tape->chrdev_direction == idetape_direction_write) {
3054 if (tape->merge_stage || tape->merge_stage_size) {
3055 printk (KERN_ERR "ide-tape: merge_stage_size should be 0 now\n");
3056 tape->merge_stage_size = 0;
3059 if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL)
3061 tape->chrdev_direction = idetape_direction_read;
3071 bytes_read = idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, 0, tape->merge_stage->bh);
3073 __idetape_kfree_stage(tape->merge_stage);
3074 tape->merge_stage = NULL;
3075 tape->chrdev_direction = idetape_direction_none;
3080 if (tape->restart_speed_control_req)
3083 rq.sector = tape->first_frame_position;
3085 if (!test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags) &&
3086 tape->nr_stages < max_stages) {
3087 new_stage = idetape_kmalloc_stage(tape);
3091 if (tape->nr_stages >= max_stages)
3093 new_stage = idetape_kmalloc_stage(tape);
3096 if (!idetape_pipeline_active(tape)) {
3097 if (tape->nr_pending_stages >= 3 * max_stages / 4) {
3098 tape->measure_insert_time = 1;
3099 tape->insert_time = jiffies;
3100 tape->insert_size = 0;
3101 tape->insert_speed = 0;
3115 idetape_tape_t *tape = drive->driver_data;
3121 if (tape->debug_level >= 4)
3122 printk(KERN_INFO "ide-tape: Reached idetape_add_chrdev_read_request, %d blocks\n", blocks);
3128 if (test_bit(IDETAPE_FILEMARK, &tape->flags))
3135 idetape_initiate_read(drive, tape->max_stages);
3136 if (tape->first_stage == NULL) {
3137 if (test_bit(IDETAPE_PIPELINE_ERROR, &tape->flags))
3139 return idetape_queue_rw_tail(drive, REQ_IDETAPE_READ, blocks, tape->merge_stage->bh);
3142 rq_ptr = &tape->first_stage->rq;
3143 bytes_read = tape->tape_block_size * (rq_ptr->nr_sectors - rq_ptr->current_nr_sectors);
3150 idetape_switch_buffers(tape, tape->first_stage);
3152 set_bit(IDETAPE_FILEMARK, &tape->flags);
3153 spin_lock_irqsave(&tape->spinlock, flags);
3155 spin_unlock_irqrestore(&tape->spinlock, flags);
3156 tape->pipeline_head++;
3158 IO_trace(IO_IDETAPE_FIFO, tape->pipeline_head, tape->buffer_head, tape->tape_head, tape->minor);
3163 if (bytes_read > blocks * tape->tape_block_size) {
3164 printk(KERN_ERR "ide-tape: bug: trying to return more bytes than requested\n");
3165 bytes_read = blocks * tape->tape_block_size;
3173 idetape_tape_t *tape = drive->driver_data;
3180 bh = tape->merge_stage->bh;
3181 count = min(tape->stage_size, bcount);
3183 blocks = count / tape->tape_block_size;
3190 idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, blocks, tape->merge_stage->bh);
3196 idetape_tape_t *tape = drive->driver_data;
3202 stage = tape->first_stage;
3205 size += tape->tape_block_size * (rq->nr_sectors-rq->current_nr_sectors);
3207 size += tape->tape_block_size;
3210 size += tape->merge_stage_size;
3215 * Rewinds the tape to the Beginning Of the current Partition (BOP).
3224 idetape_tape_t *tape = drive->driver_data;
3225 if (tape->debug_level >= 2)
3226 printk(KERN_INFO "ide-tape: Reached idetape_rewind_tape\n");
3242 * Our special ide-tape ioctl's.
3250 idetape_tape_t *tape = drive->driver_data;
3255 if (tape->debug_level >= 4)
3256 printk(KERN_INFO "ide-tape: Reached idetape_blkdev_ioctl\n");
3262 tape->best_dsc_rw_frequency = config.dsc_rw_frequency;
3263 tape->max_stages = config.nr_stages;
3266 config.dsc_rw_frequency = (int) tape->best_dsc_rw_frequency;
3267 config.nr_stages = tape->max_stages;
3279 * passing the command to the tape since we may have crossed some
3283 * the filemark is in our internal pipeline even if the tape doesn't
3288 idetape_tape_t *tape = drive->driver_data;
3296 if (!tape->capabilities.sprev)
3301 if (tape->chrdev_direction == idetape_direction_read) {
3306 tape->merge_stage_size = 0;
3307 if (test_and_clear_bit(IDETAPE_FILEMARK, &tape->flags))
3309 while (tape->first_stage != NULL) {
3312 set_bit(IDETAPE_FILEMARK, &tape->flags);
3315 spin_lock_irqsave(&tape->spinlock, flags);
3316 if (tape->first_stage == tape->active_stage) {
3326 tape->next_stage = NULL;
3327 spin_unlock_irqrestore(&tape->spinlock, flags);
3329 tape->next_stage = tape->first_stage->next;
3331 spin_unlock_irqrestore(&tape->spinlock, flags);
3332 if (tape->first_stage->rq.errors == IDETAPE_ERROR_FILEMARK)
3350 if (!tape->capabilities.sprev)
3357 printk(KERN_ERR "ide-tape: MTIO operation %d not supported\n",mt_op);
3366 * The tape is optimized to maximize throughput when it is transferring
3368 * a parameter of the specific tape (26 KB on my particular tape).
3383 struct ide_tape_obj *tape = ide_tape_f(file);
3384 ide_drive_t *drive = tape->drive;
3389 if (tape->debug_level >= 3)
3390 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_read, count %Zd\n", count);
3393 if (tape->chrdev_direction != idetape_direction_read) {
3394 if (test_bit(IDETAPE_DETECT_BS, &tape->flags))
3395 if (count > tape->tape_block_size &&
3396 (count % tape->tape_block_size) == 0)
3397 tape->user_bs_factor = count / tape->tape_block_size;
3399 if ((rc = idetape_initiate_read(drive, tape->max_stages)) < 0)
3403 if (tape->merge_stage_size) {
3404 actually_read = min((unsigned int)(tape->merge_stage_size), (unsigned int)count);
3405 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, actually_read))
3408 tape->merge_stage_size -= actually_read;
3411 while (count >= tape->stage_size) {
3412 bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl);
3415 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, bytes_read))
3422 bytes_read = idetape_add_chrdev_read_request(drive, tape->capabilities.ctl);
3426 if (idetape_copy_stage_to_user(tape, buf, tape->merge_stage, temp))
3429 tape->merge_stage_size = bytes_read-temp;
3432 if (!actually_read && test_bit(IDETAPE_FILEMARK, &tape->flags)) {
3434 if (tape->debug_level >= 2)
3435 printk(KERN_INFO "ide-tape: %s: spacing over filemark\n", tape->name);
3447 struct ide_tape_obj *tape = ide_tape_f(file);
3448 ide_drive_t *drive = tape->drive;
3453 if (tape->write_prot)
3457 if (tape->debug_level >= 3)
3458 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_write, "
3463 if (tape->chrdev_direction != idetape_direction_write) {
3464 if (tape->chrdev_direction == idetape_direction_read)
3467 if (tape->merge_stage || tape->merge_stage_size) {
3468 printk(KERN_ERR "ide-tape: merge_stage_size "
3470 tape->merge_stage_size = 0;
3473 if ((tape->merge_stage = __idetape_kmalloc_stage(tape, 0, 0)) == NULL)
3475 tape->chrdev_direction = idetape_direction_write;
3476 idetape_init_merge_stage(tape);
3486 ssize_t retval = idetape_queue_rw_tail(drive, REQ_IDETAPE_WRITE, 0, tape->merge_stage->bh);
3488 __idetape_kfree_stage(tape->merge_stage);
3489 tape->merge_stage = NULL;
3490 tape->chrdev_direction = idetape_direction_none;
3497 if (tape->restart_speed_control_req)
3499 if (tape->merge_stage_size) {
3501 if (tape->merge_stage_size >= tape->stage_size) {
3502 printk(KERN_ERR "ide-tape: bug: merge buffer too big\n");
3503 tape->merge_stage_size = 0;
3506 actually_written = min((unsigned int)(tape->stage_size - tape->merge_stage_size), (unsigned int)count);
3507 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, actually_written))
3510 tape->merge_stage_size += actually_written;
3513 if (tape->merge_stage_size == tape->stage_size) {
3515 tape->merge_stage_size = 0;
3516 retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl);
3521 while (count >= tape->stage_size) {
3523 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, tape->stage_size))
3525 buf += tape->stage_size;
3526 count -= tape->stage_size;
3527 retval = idetape_add_chrdev_write_request(drive, tape->capabilities.ctl);
3528 actually_written += tape->stage_size;
3534 if (idetape_copy_stage_from_user(tape, tape->merge_stage, buf, count))
3536 tape->merge_stage_size += count;
3548 printk(KERN_ERR "ide-tape: Couldn't write a filemark\n");
3561 * The tape is positioned after the last spaced filemark.
3563 * MTFSFM - Same as MTFSF, but the tape is positioned before the
3566 * MTBSF - Steps background over mt_count filemarks, tape is
3569 * MTBSFM - Like MTBSF, only tape is positioned after the last filemark.
3573 * MTBSF and MTBSFM are not supported when the tape doesn't
3582 * MTREW - Rewinds tape.
3584 * MTLOAD - Loads the tape.
3586 * MTOFFL - Puts the tape drive "Offline": Rewinds the tape and
3589 * MTNOP - Flushes tape buffers.
3596 * MTERASE - Erases tape.
3602 * MTSEEK - Positions the tape in a specific block number, where
3606 * MTSETPART - Switches to another tape partition.
3608 * MTLOCK - Locks the tape door.
3610 * MTUNLOCK - Unlocks the tape door.
3619 idetape_tape_t *tape = drive->driver_data;
3624 if (tape->debug_level >= 1)
3625 printk(KERN_INFO "ide-tape: Handling MTIOCTOP ioctl: "
3644 if (tape->write_prot)
3668 if (tape->door_locked) {
3671 tape->door_locked = DOOR_UNLOCKED;
3677 clear_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags);
3695 if (mt_count < tape->tape_block_size || mt_count % tape->tape_block_size)
3697 tape->user_bs_factor = mt_count / tape->tape_block_size;
3698 clear_bit(IDETAPE_DETECT_BS, &tape->flags);
3700 set_bit(IDETAPE_DETECT_BS, &tape->flags);
3704 return idetape_position_tape(drive, mt_count * tape->user_bs_factor, tape->partition, 0);
3715 tape->door_locked = DOOR_EXPLICITLY_LOCKED;
3722 tape->door_locked = DOOR_UNLOCKED;
3725 printk(KERN_ERR "ide-tape: MTIO operation %d not "
3748 * MTIOCPOS - The current tape "block position" is returned. We
3752 * Our own ide-tape ioctls are supported on both interfaces.
3756 struct ide_tape_obj *tape = ide_tape_f(file);
3757 ide_drive_t *drive = tape->drive;
3761 int block_offset = 0, position = tape->first_frame_position;
3765 if (tape->debug_level >= 3)
3766 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_ioctl, "
3770 tape->restart_speed_control_req = 1;
3771 if (tape->chrdev_direction == idetape_direction_write) {
3776 block_offset = idetape_pipeline_size(drive) / (tape->tape_block_size * tape->user_bs_factor);
3788 mtget.mt_blkno = position / tape->user_bs_factor - block_offset;
3789 mtget.mt_dsreg = ((tape->tape_block_size * tape->user_bs_factor) << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK;
3790 if (tape->drv_write_prot) {
3797 mtpos.mt_blkno = position / tape->user_bs_factor - block_offset;
3802 if (tape->chrdev_direction == idetape_direction_read)
3817 idetape_tape_t *tape;
3829 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_open\n");
3835 if (!(tape = ide_tape_chrdev_get(i)))
3838 drive = tape->drive;
3840 filp->private_data = tape;
3842 if (test_and_set_bit(IDETAPE_BUSY, &tape->flags)) {
3849 clear_bit(IDETAPE_BUSY, &tape->flags);
3850 printk(KERN_ERR "ide-tape: %s: drive not ready\n", tape->name);
3855 if (!test_bit(IDETAPE_ADDRESS_VALID, &tape->flags))
3858 if (tape->chrdev_direction != idetape_direction_read)
3859 clear_bit(IDETAPE_PIPELINE_ERROR, &tape->flags);
3866 tape->write_prot = 1;
3868 tape->write_prot = tape->drv_write_prot;
3871 if (tape->write_prot) {
3874 clear_bit(IDETAPE_BUSY, &tape->flags);
3881 * Lock the tape drive door so user can't eject.
3883 if (tape->chrdev_direction == idetape_direction_none) {
3886 if (tape->door_locked != DOOR_EXPLICITLY_LOCKED)
3887 tape->door_locked = DOOR_LOCKED;
3892 tape->restart_speed_control_req = 0;
3896 ide_tape_put(tape);
3902 idetape_tape_t *tape = drive->driver_data;
3905 tape->merge_stage = __idetape_kmalloc_stage(tape, 1, 0);
3906 if (tape->merge_stage != NULL) {
3907 idetape_pad_zeros(drive, tape->tape_block_size * (tape->user_bs_factor - 1));
3908 __idetape_kfree_stage(tape->merge_stage);
3909 tape->merge_stage = NULL;
3921 struct ide_tape_obj *tape = ide_tape_f(filp);
3922 ide_drive_t *drive = tape->drive;
3927 tape = drive->driver_data;
3929 if (tape->debug_level >= 3)
3930 printk(KERN_INFO "ide-tape: Reached idetape_chrdev_release\n");
3933 if (tape->chrdev_direction == idetape_direction_write)
3935 if (tape->chrdev_direction == idetape_direction_read) {
3941 if (tape->cache_stage != NULL) {
3942 __idetape_kfree_stage(tape->cache_stage);
3943 tape->cache_stage = NULL;
3945 if (minor < 128 && test_bit(IDETAPE_MEDIUM_PRESENT, &tape->flags))
3947 if (tape->chrdev_direction == idetape_direction_none) {
3948 if (tape->door_locked == DOOR_LOCKED) {
3951 tape->door_locked = DOOR_UNLOCKED;
3955 clear_bit(IDETAPE_BUSY, &tape->flags);
3956 ide_tape_put(tape);
3965 * 1 If the tape can be supported by us, based on the information
3968 * 0 If this tape driver is not currently supported by us.
3984 printk(KERN_INFO "ide-tape: Dumping ATAPI Identify Device tape parameters\n");
3985 printk(KERN_INFO "ide-tape: Protocol Type: ");
3989 case 3: printk("Reserved (Unknown to ide-tape)\n");break;
3991 printk(KERN_INFO "ide-tape: Device Type: %x - ",gcw.device_type);
4002 printk(KERN_INFO "ide-tape: Removable: %s",gcw.removable ? "Yes\n":"No\n");
4003 printk(KERN_INFO "ide-tape: Command Packet DRQ Type: ");
4010 printk(KERN_INFO "ide-tape: Command Packet Size: ");
4016 printk(KERN_INFO "ide-tape: Model: %.40s\n",id->model);
4017 printk(KERN_INFO "ide-tape: Firmware Revision: %.8s\n",id->fw_rev);
4018 printk(KERN_INFO "ide-tape: Serial Number: %.20s\n",id->serial_no);
4019 printk(KERN_INFO "ide-tape: Write buffer size: %d bytes\n",id->buf_size*512);
4020 printk(KERN_INFO "ide-tape: DMA: %s",id->capability & 0x01 ? "Yes\n":"No\n");
4021 printk(KERN_INFO "ide-tape: LBA: %s",id->capability & 0x02 ? "Yes\n":"No\n");
4022 printk(KERN_INFO "ide-tape: IORDY can be disabled: %s",id->capability & 0x04 ? "Yes\n":"No\n");
4023 printk(KERN_INFO "ide-tape: IORDY supported: %s",id->capability & 0x08 ? "Yes\n":"Unknown\n");
4024 printk(KERN_INFO "ide-tape: ATAPI overlap supported: %s",id->capability & 0x20 ? "Yes\n":"No\n");
4025 printk(KERN_INFO "ide-tape: PIO Cycle Timing Category: %d\n",id->tPIO);
4026 printk(KERN_INFO "ide-tape: DMA Cycle Timing Category: %d\n",id->tDMA);
4027 printk(KERN_INFO "ide-tape: Single Word DMA supported modes: ");
4035 printk(KERN_INFO "ide-tape: Multi Word DMA supported modes: ");
4044 printk(KERN_INFO "ide-tape: Enhanced PIO Modes: %s\n",
4046 printk(KERN_INFO "ide-tape: Minimum Multi-word DMA cycle per word: ");
4052 printk(KERN_INFO "ide-tape: Manufacturer\'s Recommended Multi-word cycle: ");
4058 printk(KERN_INFO "ide-tape: Minimum PIO cycle without IORDY: ");
4064 printk(KERN_INFO "ide-tape: Minimum PIO cycle with IORDY: ");
4071 printk(KERN_INFO "ide-tape: According to the device, fields 64-70 are not valid.\n");
4077 printk(KERN_ERR "ide-tape: Protocol is not ATAPI\n");
4079 printk(KERN_ERR "ide-tape: Device type is not set to tape\n");
4081 printk(KERN_ERR "ide-tape: The removable flag is not set\n");
4083 printk(KERN_ERR "ide-tape: Packet size is not 12 bytes long\n");
4085 printk(KERN_ERR "ide-tape: Sorry, padding to 16 bytes is still not supported\n");
4097 idetape_tape_t *tape = drive->driver_data;
4103 printk(KERN_ERR "ide-tape: %s: can't get INQUIRY results\n", tape->name);
4107 memcpy(tape->vendor_id, inquiry->vendor_id, 8);
4108 memcpy(tape->product_id, inquiry->product_id, 16);
4109 memcpy(tape->firmware_revision, inquiry->revision_level, 4);
4110 ide_fixstring(tape->vendor_id, 10, 0);
4111 ide_fixstring(tape->product_id, 18, 0);
4112 ide_fixstring(tape->firmware_revision, 6, 0);
4113 r = tape->firmware_revision;
4115 tape->firmware_revision_num = (*r - '0') * 100 + (*(r + 2) - '0') * 10 + *(r + 3) - '0';
4116 printk(KERN_INFO "ide-tape: %s <-> %s: %s %s rev %s\n", drive->name, tape->name, tape->vendor_id, tape->product_id, tape->firmware_revision);
4120 * idetape_get_mode_sense_results asks the tape about its various
4122 * size to the recommended value as returned by the tape.
4126 idetape_tape_t *tape = drive->driver_data;
4133 printk(KERN_ERR "ide-tape: Can't get tape parameters - assuming some default values\n");
4134 tape->tape_block_size = 512;
4135 tape->capabilities.ctl = 52;
4136 tape->capabilities.speed = 450;
4137 tape->capabilities.buffer_size = 6 * 52;
4149 printk(KERN_INFO "ide-tape: %s: overriding capabilities->speed (assuming 650KB/sec)\n", drive->name);
4153 printk(KERN_INFO "ide-tape: %s: overriding capabilities->max_speed (assuming 650KB/sec)\n", drive->name);
4157 tape->capabilities = *capabilities; /* Save us a copy */
4159 tape->tape_block_size = 512;
4161 tape->tape_block_size = 1024;
4164 printk(KERN_INFO "ide-tape: Dumping the results of the MODE SENSE packet command\n");
4165 printk(KERN_INFO "ide-tape: Mode Parameter Header:\n");
4166 printk(KERN_INFO "ide-tape: Mode Data Length - %d\n",header->mode_data_length);
4167 printk(KERN_INFO "ide-tape: Medium Type - %d\n",header->medium_type);
4168 printk(KERN_INFO "ide-tape: Device Specific Parameter - %d\n",header->dsp);
4169 printk(KERN_INFO "ide-tape: Block Descriptor Length - %d\n",header->bdl);
4171 printk(KERN_INFO "ide-tape: Capabilities and Mechanical Status Page:\n");
4172 printk(KERN_INFO "ide-tape: Page code - %d\n",capabilities->page_code);
4173 printk(KERN_INFO "ide-tape: Page length - %d\n",capabilities->page_length);
4174 printk(KERN_INFO "ide-tape: Read only - %s\n",capabilities->ro ? "Yes":"No");
4175 printk(KERN_INFO "ide-tape: Supports reverse space - %s\n",capabilities->sprev ? "Yes":"No");
4176 printk(KERN_INFO "ide-tape: Supports erase initiated formatting - %s\n",capabilities->efmt ? "Yes":"No");
4177 printk(KERN_INFO "ide-tape: Supports QFA two Partition format - %s\n",capabilities->qfa ? "Yes":"No");
4178 printk(KERN_INFO "ide-tape: Supports locking the medium - %s\n",capabilities->lock ? "Yes":"No");
4179 printk(KERN_INFO "ide-tape: The volume is currently locked - %s\n",capabilities->locked ? "Yes":"No");
4180 printk(KERN_INFO "ide-tape: The device defaults in the prevent state - %s\n",capabilities->prevent ? "Yes":"No");
4181 printk(KERN_INFO "ide-tape: Supports ejecting the medium - %s\n",capabilities->eject ? "Yes":"No");
4182 printk(KERN_INFO "ide-tape: Supports error correction - %s\n",capabilities->ecc ? "Yes":"No");
4183 printk(KERN_INFO "ide-tape: Supports data compression - %s\n",capabilities->cmprs ? "Yes":"No");
4184 printk(KERN_INFO "ide-tape: Supports 512 bytes block size - %s\n",capabilities->blk512 ? "Yes":"No");
4185 printk(KERN_INFO "ide-tape: Supports 1024 bytes block size - %s\n",capabilities->blk1024 ? "Yes":"No");
4186 printk(KERN_INFO "ide-tape: Supports 32768 bytes block size / Restricted byte count for PIO transfers - %s\n",capabilities->blk32768 ? "Yes":"No");
4187 printk(KERN_INFO "ide-tape: Maximum supported speed in KBps - %d\n",capabilities->max_speed);
4188 printk(KERN_INFO "ide-tape: Continuous transfer limits in blocks - %d\n",capabilities->ctl);
4189 printk(KERN_INFO "ide-tape: Current speed in KBps - %d\n",capabilities->speed);
4190 printk(KERN_INFO "ide-tape: Buffer size - %d\n",capabilities->buffer_size*512);
4196 * and if it succeeds sets the tape block size with the reported value
4201 idetape_tape_t *tape = drive->driver_data;
4208 printk(KERN_ERR "ide-tape: Can't get block descriptor\n");
4209 if (tape->tape_block_size == 0) {
4210 printk(KERN_WARNING "ide-tape: Cannot deal with zero block size, assume 32k\n");
4211 tape->tape_block_size = 32768;
4217 tape->tape_block_size =( block_descrp->length[0]<<16) + (block_descrp->length[1]<<8) + block_descrp->length[2];
4218 tape->drv_write_prot = (header->dsp & 0x80) >> 7;
4221 printk(KERN_INFO "ide-tape: Adjusted block size - %d\n", tape->tape_block_size);
4228 idetape_tape_t *tape = drive->driver_data;
4233 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 2, &tape->capabilities.buffer_size, NULL);
4234 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
4235 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL);
4236 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
4237 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL);
4238 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL);
4239 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 1, &tape->capabilities.speed, NULL);
4240 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL);
4241 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL);
4243 ide_add_setting(drive, "pipeline_head_speed_c",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, NULL);
4244 ide_add_setting(drive, "pipeline_head_speed_u",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->uncontrolled_pipeline_head_speed,NULL);
4245 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->avg_speed, NULL);
4246 ide_add_setting(drive, "debug_level", SETTING_RW, TYPE_INT, 0, 0xffff, 1, 1, &tape->debug_level, NULL);
4256 * 2. Ask the tape for its capabilities.
4264 static void idetape_setup (ide_drive_t *drive, idetape_tape_t *tape, int minor)
4272 spin_lock_init(&tape->spinlock);
4282 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", tape->name);
4290 tape->minor = minor;
4291 tape->name[0] = 'h';
4292 tape->name[1] = 't';
4293 tape->name[2] = '0' + minor;
4294 tape->chrdev_direction = idetape_direction_none;
4295 tape->pc = tape->pc_stack;
4296 tape->max_insert_speed = 10000;
4297 tape->speed_control = 1;
4300 set_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags);
4302 tape->min_pipeline = tape->max_pipeline = tape->max_stages = 10;
4307 tape->user_bs_factor = 1;
4308 tape->stage_size = tape->capabilities.ctl * tape->tape_block_size;
4309 while (tape->stage_size > 0xffff) {
4310 printk(KERN_NOTICE "ide-tape: decreasing stage size\n");
4311 tape->capabilities.ctl /= 2;
4312 tape->stage_size = tape->capabilities.ctl * tape->tape_block_size;
4314 stage_size = tape->stage_size;
4315 tape->pages_per_stage = stage_size / PAGE_SIZE;
4317 tape->pages_per_stage++;
4318 tape->excess_bh_size = PAGE_SIZE - stage_size % PAGE_SIZE;
4325 speed = max(tape->capabilities.speed, tape->capabilities.max_speed);
4327 tape->max_stages = speed * 1000 * 10 / tape->stage_size;
4333 if (tape->max_stages * tape->stage_size > si.totalram * si.mem_unit / 10)
4334 tape->max_stages = si.totalram * si.mem_unit / (10 * tape->stage_size);
4335 tape->max_stages = min(tape->max_stages, IDETAPE_MAX_PIPELINE_STAGES);
4336 tape->min_pipeline = min(tape->max_stages, IDETAPE_MIN_PIPELINE_STAGES);
4337 tape->max_pipeline = min(tape->max_stages * 2, IDETAPE_MAX_PIPELINE_STAGES);
4338 if (tape->max_stages == 0)
4339 tape->max_stages = tape->min_pipeline = tape->max_pipeline = 1;
4341 t1 = (tape->stage_size * HZ) / (speed * 1000);
4342 tmid = (tape->capabilities.buffer_size * 32 * HZ) / (speed * 125);
4343 tn = (IDETAPE_FIFO_THRESHOLD * tape->stage_size * HZ) / (speed * 1000);
4345 if (tape->max_stages)
4354 tape->best_dsc_rw_frequency = max_t(unsigned long, min_t(unsigned long, t, IDETAPE_DSC_RW_MAX), IDETAPE_DSC_RW_MIN);
4355 printk(KERN_INFO "ide-tape: %s <-> %s: %dKBps, %d*%dkB buffer, "
4357 drive->name, tape->name, tape->capabilities.speed,
4358 (tape->capabilities.buffer_size * 512) / tape->stage_size,
4359 tape->stage_size / 1024,
4360 tape->max_stages * tape->stage_size / 1024,
4361 tape->best_dsc_rw_frequency * 1000 / HZ,
4369 idetape_tape_t *tape = drive->driver_data;
4371 ide_proc_unregister_driver(drive, tape->driver);
4373 ide_unregister_region(tape->disk);
4375 ide_tape_put(tape);
4380 struct ide_tape_obj *tape = to_ide_tape(kref);
4381 ide_drive_t *drive = tape->drive;
4382 struct gendisk *g = tape->disk;
4384 BUG_ON(tape->first_stage != NULL || tape->merge_stage_size);
4389 MKDEV(IDETAPE_MAJOR, tape->minor));
4391 MKDEV(IDETAPE_MAJOR, tape->minor + 128));
4392 idetape_devs[tape->minor] = NULL;
4395 kfree(tape);
4403 idetape_tape_t *tape = drive->driver_data;
4407 len = sprintf(out, "%s\n", tape->name);
4423 .name = "ide-tape",
4455 struct ide_tape_obj *tape;
4457 if (!(tape = ide_tape_get(disk)))
4466 struct ide_tape_obj *tape = ide_tape_g(disk);
4468 ide_tape_put(tape);
4477 struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk);
4478 ide_drive_t *drive = tape->drive;
4494 idetape_tape_t *tape;
4498 if (!strstr("ide-tape", drive->driver_req))
4505 printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
4509 printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name);
4513 printk(KERN_WARNING "ide-tape: Use drive %s with ide-scsi emulation and osst.\n", drive->name);
4514 printk(KERN_WARNING "ide-tape: OnStream support will be removed soon from ide-tape!\n");
4516 tape = kzalloc(sizeof (idetape_tape_t), GFP_KERNEL);
4517 if (tape == NULL) {
4518 printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name);
4530 kref_init(&tape->kref);
4532 tape->drive = drive;
4533 tape->driver = &idetape_driver;
4534 tape->disk = g;
4536 g->private_data = &tape->driver;
4538 drive->driver_data = tape;
4543 idetape_devs[minor] = tape;
4546 idetape_setup(drive, tape, minor);
4549 MKDEV(IDETAPE_MAJOR, minor), &drive->gendev, "%s", tape->name);
4551 MKDEV(IDETAPE_MAJOR, minor + 128), &drive->gendev, "n%s", tape->name);
4559 kfree(tape);
4586 printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
4605 MODULE_ALIAS("ide:*m-tape*");