st.h 7.3 KB

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