📄 ide-tape.c
字号:
* case we can't allocate stages, we just manage without them * (at the expense of decreased throughput) so when Linux is * tight in memory, we will not pose additional difficulties. * * 2. The maximum number of stages (which is, in fact, the maximum * amount of memory) which we allocate is limited by the compile * time parameter IDETAPE_MAX_PIPELINE_STAGES. * * 3. The maximum number of stages is a controlled parameter - We * don't start from the user defined maximum number of stages * but from the lower IDETAPE_MIN_PIPELINE_STAGES (again, we * will not even allocate this amount of stages if the user * program can't handle the speed). We then implement a feedback * loop which checks if the pipeline is empty, and if it is, we * increase the maximum number of stages as necessary until we * reach the optimum value which just manages to keep the tape * busy with minimum allocated memory or until we reach * IDETAPE_MAX_PIPELINE_STAGES. * * Concerning (2): * * In pipelined write mode, ide-tape can not return accurate error codes * to the user program since we usually just add the request to the * pipeline without waiting for it to be serviced. In case an error * occurs, I will report it on the next user request. * * In the pipelined read mode, subsequent read requests or forward * filemark spacing will perform correctly, as we preserve all blocks * and filemarks which we encountered during our excess read-ahead. * * For accurate tape positioning and error reporting, disabling * pipelined mode might be the best option. * * You can enable/disable/tune the pipelined operation mode by adjusting * the compile time parameters below. *//* * Possible improvements. * * 1. Support for the ATAPI overlap protocol. * * In order to maximize bus throughput, we currently use the DSC * overlap method which enables ide.c to service requests from the * other device while the tape is busy executing a command. The * DSC overlap method involves polling the tape's status register * for the DSC bit, and servicing the other device while the tape * isn't ready. * * In the current QIC development standard (December 1995), * it is recommended that new tape drives will *in addition* * implement the ATAPI overlap protocol, which is used for the * same purpose - efficient use of the IDE bus, but is interrupt * driven and thus has much less CPU overhead. * * ATAPI overlap is likely to be supported in most new ATAPI * devices, including new ATAPI cdroms, and thus provides us * a method by which we can achieve higher throughput when * sharing a (fast) ATA-2 disk with any (slow) new ATAPI device. */#define IDETAPE_VERSION "1.19"#include <linux/module.h>#include <linux/types.h>#include <linux/string.h>#include <linux/kernel.h>#include <linux/delay.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/interrupt.h>#include <linux/jiffies.h>#include <linux/major.h>#include <linux/errno.h>#include <linux/genhd.h>#include <linux/slab.h>#include <linux/pci.h>#include <linux/ide.h>#include <linux/smp_lock.h>#include <linux/completion.h>#include <linux/bitops.h>#include <linux/mutex.h>#include <asm/byteorder.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/unaligned.h>/* * partition */typedef struct os_partition_s { __u8 partition_num; __u8 par_desc_ver; __u16 wrt_pass_cntr; __u32 first_frame_addr; __u32 last_frame_addr; __u32 eod_frame_addr;} os_partition_t;/* * DAT entry */typedef struct os_dat_entry_s { __u32 blk_sz; __u16 blk_cnt; __u8 flags; __u8 reserved;} os_dat_entry_t;/* * DAT */#define OS_DAT_FLAGS_DATA (0xc)#define OS_DAT_FLAGS_MARK (0x1)typedef struct os_dat_s { __u8 dat_sz; __u8 reserved1; __u8 entry_cnt; __u8 reserved3; os_dat_entry_t dat_list[16];} os_dat_t;#include <linux/mtio.h>/**************************** Tunable parameters *****************************//* * Pipelined mode parameters. * * We try to use the minimum number of stages which is enough to * keep the tape constantly streaming. To accomplish that, we implement * a feedback loop around the maximum number of stages: * * We start from MIN maximum stages (we will not even use MIN stages * if we don't need them), increment it by RATE*(MAX-MIN) * whenever we sense that the pipeline is empty, until we reach * the optimum value or until we reach MAX. * * Setting the following parameter to 0 is illegal: the pipelined mode * cannot be disabled (calculate_speeds() divides by tape->max_stages.) */#define IDETAPE_MIN_PIPELINE_STAGES 1#define IDETAPE_MAX_PIPELINE_STAGES 400#define IDETAPE_INCREASE_STAGES_RATE 20/* * The following are used to debug the driver: * * Setting IDETAPE_DEBUG_INFO to 1 will report device capabilities. * Setting IDETAPE_DEBUG_LOG to 1 will log driver flow control. * Setting IDETAPE_DEBUG_BUGS to 1 will enable self-sanity checks in * some places. * * Setting them to 0 will restore normal operation mode: * * 1. Disable logging normal successful operations. * 2. Disable self-sanity checks. * 3. Errors will still be logged, of course. * * All the #if DEBUG code will be removed some day, when the driver * is verified to be stable enough. This will make it much more * esthetic. */#define IDETAPE_DEBUG_INFO 0#define IDETAPE_DEBUG_LOG 0#define IDETAPE_DEBUG_BUGS 1/* * After each failed packet command we issue a request sense command * and retry the packet command IDETAPE_MAX_PC_RETRIES times. * * Setting IDETAPE_MAX_PC_RETRIES to 0 will disable retries. */#define IDETAPE_MAX_PC_RETRIES 3/* * With each packet command, we allocate a buffer of * IDETAPE_PC_BUFFER_SIZE bytes. This is used for several packet * commands (Not for READ/WRITE commands). */#define IDETAPE_PC_BUFFER_SIZE 256/* * In various places in the driver, we need to allocate storage * for packet commands and requests, which will remain valid while * we leave the driver to wait for an interrupt or a timeout event. */#define IDETAPE_PC_STACK (10 + IDETAPE_MAX_PC_RETRIES)/* * Some drives (for example, Seagate STT3401A Travan) require a very long * timeout, because they don't return an interrupt or clear their busy bit * until after the command completes (even retension commands). */#define IDETAPE_WAIT_CMD (900*HZ)/* * The following parameter is used to select the point in the internal * tape fifo in which we will start to refill the buffer. Decreasing * the following parameter will improve the system's latency and * interactive response, while using a high value might improve system * throughput. */#define IDETAPE_FIFO_THRESHOLD 2/* * DSC polling parameters. * * Polling for DSC (a single bit in the status register) is a very * important function in ide-tape. There are two cases in which we * poll for DSC: * * 1. Before a read/write packet command, to ensure that we * can transfer data from/to the tape's data buffers, without * causing an actual media access. In case the tape is not * ready yet, we take out our request from the device * request queue, so that ide.c will service requests from * the other device on the same interface meanwhile. * * 2. After the successful initialization of a "media access * packet command", which is a command which can take a long * time to complete (it can be several seconds or even an hour). * * Again, we postpone our request in the middle to free the bus * for the other device. The polling frequency here should be * lower than the read/write frequency since those media access * commands are slow. We start from a "fast" frequency - * IDETAPE_DSC_MA_FAST (one second), and if we don't receive DSC * after IDETAPE_DSC_MA_THRESHOLD (5 minutes), we switch it to a * lower frequency - IDETAPE_DSC_MA_SLOW (1 minute). * * We also set a timeout for the timer, in case something goes wrong. * The timeout should be longer then the maximum execution time of a * tape operation. */ /* * DSC timings. */#define IDETAPE_DSC_RW_MIN 5*HZ/100 /* 50 msec */#define IDETAPE_DSC_RW_MAX 40*HZ/100 /* 400 msec */#define IDETAPE_DSC_RW_TIMEOUT 2*60*HZ /* 2 minutes */#define IDETAPE_DSC_MA_FAST 2*HZ /* 2 seconds */#define IDETAPE_DSC_MA_THRESHOLD 5*60*HZ /* 5 minutes */#define IDETAPE_DSC_MA_SLOW 30*HZ /* 30 seconds */#define IDETAPE_DSC_MA_TIMEOUT 2*60*60*HZ /* 2 hours *//*************************** End of tunable parameters ***********************//* * Debugging/Performance analysis * * I/O trace support */#define USE_IOTRACE 0#if USE_IOTRACE#define IO_IDETAPE_FIFO 500#endif/* * Read/Write error simulation */#define SIMULATE_ERRORS 0/* * For general magnetic tape device compatibility. */typedef enum { idetape_direction_none, idetape_direction_read, idetape_direction_write} idetape_chrdev_direction_t;struct idetape_bh { u32 b_size; atomic_t b_count; struct idetape_bh *b_reqnext; char *b_data;};/* * Our view of a packet command. */typedef struct idetape_packet_command_s { u8 c[12]; /* Actual packet bytes */ int retries; /* On each retry, we increment retries */ int error; /* Error code */ int request_transfer; /* Bytes to transfer */ int actually_transferred; /* Bytes actually transferred */ int buffer_size; /* Size of our data buffer */ struct idetape_bh *bh; char *b_data; int b_count; u8 *buffer; /* Data buffer */ u8 *current_position; /* Pointer into the above buffer */ ide_startstop_t (*callback) (ide_drive_t *); /* Called when this packet command is completed */ u8 pc_buffer[IDETAPE_PC_BUFFER_SIZE]; /* Temporary buffer */ unsigned long flags; /* Status/Action bit flags: long for set_bit */} idetape_pc_t;/* * Packet command flag bits. *//* Set when an error is considered normal - We won't retry */#define PC_ABORT 0/* 1 When polling for DSC on a media access command */#define PC_WAIT_FOR_DSC 1/* 1 when we prefer to use DMA if possible */#define PC_DMA_RECOMMENDED 2/* 1 while DMA in progress */#define PC_DMA_IN_PROGRESS 3/* 1 when encountered problem during DMA */#define PC_DMA_ERROR 4/* Data direction */#define PC_WRITING 5/* * Capabilities and Mechanical Status Page */typedef struct { unsigned page_code :6; /* Page code - Should be 0x2a */ __u8 reserved0_6 :1; __u8 ps :1; /* parameters saveable */ __u8 page_length; /* Page Length - Should be 0x12 */ __u8 reserved2, reserved3; unsigned ro :1; /* Read Only Mode */ unsigned reserved4_1234 :4; unsigned sprev :1; /* Supports SPACE in the reverse direction */ unsigned reserved4_67 :2; unsigned reserved5_012 :3; unsigned efmt :1; /* Supports ERASE command initiated formatting */ unsigned reserved5_4 :1; unsigned qfa :1; /* Supports the QFA two partition formats */ unsigned reserved5_67 :2; unsigned lock :1; /* Supports locking the volume */ unsigned locked :1; /* The volume is locked */ unsigned prevent :1; /* The device defaults in the prevent state after power up */ unsigned eject :1; /* The device can eject the volume */ __u8 disconnect :1; /* The device can break request > ctl */ __u8 reserved6_5 :1; unsigned ecc :1; /* Supports error correction */ unsigned cmprs :1; /* Supports data compression */ unsigned reserved7_0 :1; unsigned blk512 :1; /* Supports 512 bytes block size */ unsigned blk1024 :1; /* Supports 1024 bytes block size */ unsigned reserved7_3_6 :4; unsigned blk32768 :1; /* slowb - the device restricts the byte count for PIO */ /* transfers for slow buffer memory ??? */ /* Also 32768 block size in some cases */ __u16 max_speed; /* Maximum speed supported in KBps */ __u8 reserved10, reserved11; __u16 ctl; /* Continuous Transfer Limit in blocks */ __u16 speed; /* Current Speed, in KBps */ __u16 buffer_size; /* Buffer Size, in 512 bytes */ __u8 reserved18, reserved19;} idetape_capabilities_page_t;/* * Block Size Page
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -