st.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #ifndef _ST_H
  2. #define _ST_H
  3. #include <linux/completion.h>
  4. #include <linux/mutex.h>
  5. #include <linux/kref.h>
  6. #include <scsi/scsi_cmnd.h>
  7. /* Descriptor for analyzed sense data */
  8. struct st_cmdstatus {
  9. int midlevel_result;
  10. struct scsi_sense_hdr sense_hdr;
  11. int have_sense;
  12. int residual;
  13. u64 uremainder64;
  14. u8 flags;
  15. u8 remainder_valid;
  16. u8 fixed_format;
  17. u8 deferred;
  18. };
  19. struct scsi_tape;
  20. /* scsi tape command */
  21. struct st_request {
  22. unsigned char cmd[MAX_COMMAND_SIZE];
  23. unsigned char sense[SCSI_SENSE_BUFFERSIZE];
  24. int result;
  25. struct scsi_tape *stp;
  26. struct completion *waiting;
  27. struct bio *bio;
  28. };
  29. /* The tape buffer descriptor. */
  30. struct st_buffer {
  31. unsigned char dma; /* DMA-able buffer */
  32. unsigned char cleared; /* internal buffer cleared after open? */
  33. unsigned short do_dio; /* direct i/o set up? */
  34. int buffer_size;
  35. int buffer_blocks;
  36. int buffer_bytes;
  37. int read_pointer;
  38. int writing;
  39. int syscall_result;
  40. struct st_request *last_SRpnt;
  41. struct st_cmdstatus cmdstat;
  42. struct page **reserved_pages;
  43. int reserved_page_order;
  44. struct page **mapped_pages;
  45. struct rq_map_data map_data;
  46. unsigned char *b_data;
  47. unsigned short use_sg; /* zero or max number of s/g segments for this adapter */
  48. unsigned short sg_segs; /* number of segments in s/g list */
  49. unsigned short frp_segs; /* number of buffer segments */
  50. };
  51. /* The tape mode definition */
  52. struct st_modedef {
  53. unsigned char defined;
  54. unsigned char sysv; /* SYS V semantics? */
  55. unsigned char do_async_writes;
  56. unsigned char do_buffer_writes;
  57. unsigned char do_read_ahead;
  58. unsigned char defaults_for_writes;
  59. unsigned char default_compression; /* 0 = don't touch, etc */
  60. short default_density; /* Forced density, -1 = no value */
  61. int default_blksize; /* Forced blocksize, -1 = no value */
  62. struct scsi_tape *tape;
  63. struct device *devs[2]; /* Auto-rewind and non-rewind devices */
  64. struct cdev *cdevs[2]; /* Auto-rewind and non-rewind devices */
  65. };
  66. /* Number of modes can be changed by changing ST_NBR_MODE_BITS. The maximum
  67. number of modes is 16 (ST_NBR_MODE_BITS 4) */
  68. #define ST_NBR_MODE_BITS 2
  69. #define ST_NBR_MODES (1 << ST_NBR_MODE_BITS)
  70. #define ST_MODE_SHIFT (7 - ST_NBR_MODE_BITS)
  71. #define ST_MODE_MASK ((ST_NBR_MODES - 1) << ST_MODE_SHIFT)
  72. #define ST_MAX_TAPES (1 << (20 - (ST_NBR_MODE_BITS + 1)))
  73. #define ST_MAX_TAPE_ENTRIES (ST_MAX_TAPES << (ST_NBR_MODE_BITS + 1))
  74. /* The status related to each partition */
  75. struct st_partstat {
  76. unsigned char rw;
  77. unsigned char eof;
  78. unsigned char at_sm;
  79. unsigned char last_block_valid;
  80. u32 last_block_visited;
  81. int drv_block; /* The block where the drive head is */
  82. int drv_file;
  83. };
  84. /* Tape statistics */
  85. struct scsi_tape_stats {
  86. atomic64_t read_byte_cnt; /* bytes read */
  87. atomic64_t write_byte_cnt; /* bytes written */
  88. atomic64_t in_flight; /* Number of I/Os in flight */
  89. atomic64_t read_cnt; /* Count of read requests */
  90. atomic64_t write_cnt; /* Count of write requests */
  91. atomic64_t other_cnt; /* Count of other requests either
  92. * implicit or from user space
  93. * ioctl. */
  94. atomic64_t resid_cnt; /* Count of resid_len > 0 */
  95. atomic64_t tot_read_time; /* ktime spent completing reads */
  96. atomic64_t tot_write_time; /* ktime spent completing writes */
  97. atomic64_t tot_io_time; /* ktime spent doing any I/O */
  98. ktime_t read_time; /* holds ktime request was queued */
  99. ktime_t write_time; /* holds ktime request was queued */
  100. ktime_t other_time; /* holds ktime request was queued */
  101. atomic_t last_read_size; /* Number of bytes issued for last read */
  102. atomic_t last_write_size; /* Number of bytes issued for last write */
  103. };
  104. #define ST_NBR_PARTITIONS 4
  105. /* The tape drive descriptor */
  106. struct scsi_tape {
  107. struct scsi_driver *driver;
  108. struct scsi_device *device;
  109. struct mutex lock; /* For serialization */
  110. struct completion wait; /* For SCSI commands */
  111. struct st_buffer *buffer;
  112. int index;
  113. /* Drive characteristics */
  114. unsigned char omit_blklims;
  115. unsigned char do_auto_lock;
  116. unsigned char can_bsr;
  117. unsigned char can_partitions;
  118. unsigned char two_fm;
  119. unsigned char fast_mteom;
  120. unsigned char immediate;
  121. unsigned char restr_dma;
  122. unsigned char scsi2_logical;
  123. unsigned char default_drvbuffer; /* 0xff = don't touch, value 3 bits */
  124. unsigned char cln_mode; /* 0 = none, otherwise sense byte nbr */
  125. unsigned char cln_sense_value;
  126. unsigned char cln_sense_mask;
  127. unsigned char use_pf; /* Set Page Format bit in all mode selects? */
  128. unsigned char try_dio; /* try direct i/o in general? */
  129. unsigned char try_dio_now; /* try direct i/o before next close? */
  130. unsigned char c_algo; /* compression algorithm */
  131. unsigned char pos_unknown; /* after reset position unknown */
  132. unsigned char sili; /* use SILI when reading in variable b mode */
  133. unsigned char immediate_filemark; /* write filemark immediately */
  134. int tape_type;
  135. int long_timeout; /* timeout for commands known to take long time */
  136. /* Mode characteristics */
  137. struct st_modedef modes[ST_NBR_MODES];
  138. int current_mode;
  139. /* Status variables */
  140. int partition;
  141. int new_partition;
  142. int nbr_partitions; /* zero until partition support enabled */
  143. struct st_partstat ps[ST_NBR_PARTITIONS];
  144. unsigned char dirty;
  145. unsigned char ready;
  146. unsigned char write_prot;
  147. unsigned char drv_write_prot;
  148. unsigned char in_use;
  149. unsigned char blksize_changed;
  150. unsigned char density_changed;
  151. unsigned char compression_changed;
  152. unsigned char drv_buffer;
  153. unsigned char density;
  154. unsigned char door_locked;
  155. unsigned char autorew_dev; /* auto-rewind device */
  156. unsigned char rew_at_close; /* rewind necessary at close */
  157. unsigned char inited;
  158. unsigned char cleaning_req; /* cleaning requested? */
  159. int block_size;
  160. int min_block;
  161. int max_block;
  162. int recover_count; /* From tape opening */
  163. int recover_reg; /* From last status call */
  164. #if DEBUG
  165. unsigned char write_pending;
  166. int nbr_finished;
  167. int nbr_waits;
  168. int nbr_requests;
  169. int nbr_dio;
  170. int nbr_pages;
  171. unsigned char last_cmnd[6];
  172. unsigned char last_sense[16];
  173. #endif
  174. struct gendisk *disk;
  175. struct kref kref;
  176. struct scsi_tape_stats *stats;
  177. };
  178. /* Bit masks for use_pf */
  179. #define USE_PF 1
  180. #define PF_TESTED 2
  181. /* Values of eof */
  182. #define ST_NOEOF 0
  183. #define ST_FM_HIT 1
  184. #define ST_FM 2
  185. #define ST_EOM_OK 3
  186. #define ST_EOM_ERROR 4
  187. #define ST_EOD_1 5
  188. #define ST_EOD_2 6
  189. #define ST_EOD 7
  190. /* EOD hit while reading => ST_EOD_1 => return zero => ST_EOD_2 =>
  191. return zero => ST_EOD, return ENOSPC */
  192. /* When writing: ST_EOM_OK == early warning found, write OK
  193. ST_EOD_1 == allow trying new write after early warning
  194. ST_EOM_ERROR == early warning found, not able to write all */
  195. /* Values of rw */
  196. #define ST_IDLE 0
  197. #define ST_READING 1
  198. #define ST_WRITING 2
  199. /* Values of ready state */
  200. #define ST_READY 0
  201. #define ST_NOT_READY 1
  202. #define ST_NO_TAPE 2
  203. /* Values for door lock state */
  204. #define ST_UNLOCKED 0
  205. #define ST_LOCKED_EXPLICIT 1
  206. #define ST_LOCKED_AUTO 2
  207. #define ST_LOCK_FAILS 3
  208. /* Positioning SCSI-commands for Tandberg, etc. drives */
  209. #define QFA_REQUEST_BLOCK 0x02
  210. #define QFA_SEEK_BLOCK 0x0c
  211. /* Setting the binary options */
  212. #define ST_DONT_TOUCH 0
  213. #define ST_NO 1
  214. #define ST_YES 2
  215. #define EXTENDED_SENSE_START 18
  216. /* Masks for some conditions in the sense data */
  217. #define SENSE_FMK 0x80
  218. #define SENSE_EOM 0x40
  219. #define SENSE_ILI 0x20
  220. #endif