Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 
0003 #ifndef _ST_H
0004 #define _ST_H
0005 
0006 #include <linux/completion.h>
0007 #include <linux/mutex.h>
0008 #include <linux/kref.h>
0009 #include <scsi/scsi_cmnd.h>
0010 
0011 /* Descriptor for analyzed sense data */
0012 struct st_cmdstatus {
0013     int midlevel_result;
0014     struct scsi_sense_hdr sense_hdr;
0015     int have_sense;
0016     int residual;
0017     u64 uremainder64;
0018     u8 flags;
0019     u8 remainder_valid;
0020     u8 fixed_format;
0021     u8 deferred;
0022 };
0023 
0024 struct scsi_tape;
0025 
0026 /* scsi tape command */
0027 struct st_request {
0028     unsigned char cmd[MAX_COMMAND_SIZE];
0029     unsigned char sense[SCSI_SENSE_BUFFERSIZE];
0030     int result;
0031     struct scsi_tape *stp;
0032     struct completion *waiting;
0033     struct bio *bio;
0034 };
0035 
0036 /* The tape buffer descriptor. */
0037 struct st_buffer {
0038     unsigned char cleared;  /* internal buffer cleared after open? */
0039     unsigned short do_dio;  /* direct i/o set up? */
0040     int buffer_size;
0041     int buffer_blocks;
0042     int buffer_bytes;
0043     int read_pointer;
0044     int writing;
0045     int syscall_result;
0046     struct st_request *last_SRpnt;
0047     struct st_cmdstatus cmdstat;
0048     struct page **reserved_pages;
0049     int reserved_page_order;
0050     struct page **mapped_pages;
0051     struct rq_map_data map_data;
0052     unsigned char *b_data;
0053     unsigned short use_sg;  /* zero or max number of s/g segments for this adapter */
0054     unsigned short sg_segs;     /* number of segments in s/g list */
0055     unsigned short frp_segs;    /* number of buffer segments */
0056 };
0057 
0058 /* The tape mode definition */
0059 struct st_modedef {
0060     unsigned char defined;
0061     unsigned char sysv; /* SYS V semantics? */
0062     unsigned char do_async_writes;
0063     unsigned char do_buffer_writes;
0064     unsigned char do_read_ahead;
0065     unsigned char defaults_for_writes;
0066     unsigned char default_compression;  /* 0 = don't touch, etc */
0067     short default_density;  /* Forced density, -1 = no value */
0068     int default_blksize;    /* Forced blocksize, -1 = no value */
0069     struct scsi_tape *tape;
0070     struct device *devs[2];  /* Auto-rewind and non-rewind devices */
0071     struct cdev *cdevs[2];  /* Auto-rewind and non-rewind devices */
0072 };
0073 
0074 /* Number of modes can be changed by changing ST_NBR_MODE_BITS. The maximum
0075    number of modes is 16 (ST_NBR_MODE_BITS 4) */
0076 #define ST_NBR_MODE_BITS 2
0077 #define ST_NBR_MODES (1 << ST_NBR_MODE_BITS)
0078 #define ST_MODE_SHIFT (7 - ST_NBR_MODE_BITS)
0079 #define ST_MODE_MASK ((ST_NBR_MODES - 1) << ST_MODE_SHIFT)
0080 
0081 #define ST_MAX_TAPES (1 << (20 - (ST_NBR_MODE_BITS + 1)))
0082 #define ST_MAX_TAPE_ENTRIES  (ST_MAX_TAPES << (ST_NBR_MODE_BITS + 1))
0083 
0084 /* The status related to each partition */
0085 struct st_partstat {
0086     unsigned char rw;
0087     unsigned char eof;
0088     unsigned char at_sm;
0089     unsigned char last_block_valid;
0090     u32 last_block_visited;
0091     int drv_block;      /* The block where the drive head is */
0092     int drv_file;
0093 };
0094 
0095 /* Tape statistics */
0096 struct scsi_tape_stats {
0097     atomic64_t read_byte_cnt;  /* bytes read */
0098     atomic64_t write_byte_cnt; /* bytes written */
0099     atomic64_t in_flight;      /* Number of I/Os in flight */
0100     atomic64_t read_cnt;       /* Count of read requests */
0101     atomic64_t write_cnt;      /* Count of write requests */
0102     atomic64_t other_cnt;      /* Count of other requests either
0103                     * implicit or from user space
0104                     * ioctl. */
0105     atomic64_t resid_cnt;      /* Count of resid_len > 0 */
0106     atomic64_t tot_read_time;  /* ktime spent completing reads */
0107     atomic64_t tot_write_time; /* ktime spent completing writes */
0108     atomic64_t tot_io_time;    /* ktime spent doing any I/O */
0109     ktime_t read_time;         /* holds ktime request was queued */
0110     ktime_t write_time;        /* holds ktime request was queued */
0111     ktime_t other_time;        /* holds ktime request was queued */
0112     atomic_t last_read_size;   /* Number of bytes issued for last read */
0113     atomic_t last_write_size;  /* Number of bytes issued for last write */
0114 };
0115 
0116 #define ST_NBR_PARTITIONS 4
0117 
0118 /* The tape drive descriptor */
0119 struct scsi_tape {
0120     struct scsi_device *device;
0121     struct mutex lock;  /* For serialization */
0122     struct completion wait; /* For SCSI commands */
0123     struct st_buffer *buffer;
0124     int index;
0125 
0126     /* Drive characteristics */
0127     unsigned char omit_blklims;
0128     unsigned char do_auto_lock;
0129     unsigned char can_bsr;
0130     unsigned char can_partitions;
0131     unsigned char two_fm;
0132     unsigned char fast_mteom;
0133     unsigned char immediate;
0134     unsigned char scsi2_logical;
0135     unsigned char default_drvbuffer;    /* 0xff = don't touch, value 3 bits */
0136     unsigned char cln_mode;         /* 0 = none, otherwise sense byte nbr */
0137     unsigned char cln_sense_value;
0138     unsigned char cln_sense_mask;
0139     unsigned char use_pf;           /* Set Page Format bit in all mode selects? */
0140     unsigned char try_dio;          /* try direct i/o in general? */
0141     unsigned char try_dio_now;      /* try direct i/o before next close? */
0142     unsigned char c_algo;           /* compression algorithm */
0143     unsigned char pos_unknown;          /* after reset position unknown */
0144     unsigned char sili;         /* use SILI when reading in variable b mode */
0145     unsigned char immediate_filemark;   /* write filemark immediately */
0146     int tape_type;
0147     int long_timeout;   /* timeout for commands known to take long time */
0148 
0149     /* Mode characteristics */
0150     struct st_modedef modes[ST_NBR_MODES];
0151     int current_mode;
0152 
0153     /* Status variables */
0154     int partition;
0155     int new_partition;
0156     int nbr_partitions; /* zero until partition support enabled */
0157     struct st_partstat ps[ST_NBR_PARTITIONS];
0158     unsigned char dirty;
0159     unsigned char ready;
0160     unsigned char write_prot;
0161     unsigned char drv_write_prot;
0162     unsigned char in_use;
0163     unsigned char blksize_changed;
0164     unsigned char density_changed;
0165     unsigned char compression_changed;
0166     unsigned char drv_buffer;
0167     unsigned char density;
0168     unsigned char door_locked;
0169     unsigned char autorew_dev;   /* auto-rewind device */
0170     unsigned char rew_at_close;  /* rewind necessary at close */
0171     unsigned char inited;
0172     unsigned char cleaning_req;  /* cleaning requested? */
0173     int block_size;
0174     int min_block;
0175     int max_block;
0176     int recover_count;     /* From tape opening */
0177     int recover_reg;       /* From last status call */
0178 
0179 #if DEBUG
0180     unsigned char write_pending;
0181     int nbr_finished;
0182     int nbr_waits;
0183     int nbr_requests;
0184     int nbr_dio;
0185     int nbr_pages;
0186     unsigned char last_cmnd[6];
0187     unsigned char last_sense[16];
0188 #endif
0189     char name[DISK_NAME_LEN];
0190     struct kref     kref;
0191     struct scsi_tape_stats *stats;
0192 };
0193 
0194 /* Bit masks for use_pf */
0195 #define USE_PF      1
0196 #define PF_TESTED   2
0197 
0198 /* Values of eof */
0199 #define ST_NOEOF    0
0200 #define ST_FM_HIT       1
0201 #define ST_FM           2
0202 #define ST_EOM_OK       3
0203 #define ST_EOM_ERROR    4
0204 #define ST_EOD_1        5
0205 #define ST_EOD_2        6
0206 #define ST_EOD      7
0207 /* EOD hit while reading => ST_EOD_1 => return zero => ST_EOD_2 =>
0208    return zero => ST_EOD, return ENOSPC */
0209 /* When writing: ST_EOM_OK == early warning found, write OK
0210          ST_EOD_1  == allow trying new write after early warning
0211          ST_EOM_ERROR == early warning found, not able to write all */
0212 
0213 /* Values of rw */
0214 #define ST_IDLE     0
0215 #define ST_READING  1
0216 #define ST_WRITING  2
0217 
0218 /* Values of ready state */
0219 #define ST_READY    0
0220 #define ST_NOT_READY    1
0221 #define ST_NO_TAPE  2
0222 
0223 /* Values for door lock state */
0224 #define ST_UNLOCKED 0
0225 #define ST_LOCKED_EXPLICIT 1
0226 #define ST_LOCKED_AUTO  2
0227 #define ST_LOCK_FAILS   3
0228 
0229 /* Positioning SCSI-commands for Tandberg, etc. drives */
0230 #define QFA_REQUEST_BLOCK   0x02
0231 #define QFA_SEEK_BLOCK      0x0c
0232 
0233 /* Setting the binary options */
0234 #define ST_DONT_TOUCH  0
0235 #define ST_NO          1
0236 #define ST_YES         2
0237 
0238 #define EXTENDED_SENSE_START  18
0239 
0240 /* Masks for some conditions in the sense data */
0241 #define SENSE_FMK   0x80
0242 #define SENSE_EOM   0x40
0243 #define SENSE_ILI   0x20
0244 
0245 #endif