st.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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 do_dio; /* direct i/o set up? */
  33. unsigned char cleared; /* internal buffer cleared after open? */
  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. struct page **mapped_pages;
  44. struct rq_map_data map_data;
  45. unsigned char *b_data;
  46. unsigned short use_sg; /* zero or max number of s/g segments for this adapter */
  47. unsigned short sg_segs; /* number of segments in s/g list */
  48. unsigned short frp_segs; /* number of buffer segments */
  49. };
  50. /* The tape mode definition */
  51. struct st_modedef {
  52. unsigned char defined;
  53. unsigned char sysv; /* SYS V semantics? */
  54. unsigned char do_async_writes;
  55. unsigned char do_buffer_writes;
  56. unsigned char do_read_ahead;
  57. unsigned char defaults_for_writes;
  58. unsigned char default_compression; /* 0 = don't touch, etc */
  59. short default_density; /* Forced density, -1 = no value */
  60. int default_blksize; /* Forced blocksize, -1 = no value */
  61. struct cdev *cdevs[2]; /* Auto-rewind and non-rewind devices */
  62. };
  63. /* Number of modes can be changed by changing ST_NBR_MODE_BITS. The maximum
  64. number of modes is 16 (ST_NBR_MODE_BITS 4) */
  65. #define ST_NBR_MODE_BITS 2
  66. #define ST_NBR_MODES (1 << ST_NBR_MODE_BITS)
  67. #define ST_MODE_SHIFT (7 - ST_NBR_MODE_BITS)
  68. #define ST_MODE_MASK ((ST_NBR_MODES - 1) << ST_MODE_SHIFT)
  69. #define ST_MAX_TAPES 128
  70. #define ST_MAX_TAPE_ENTRIES (ST_MAX_TAPES << (ST_NBR_MODE_BITS + 1))
  71. /* The status related to each partition */
  72. struct st_partstat {
  73. unsigned char rw;
  74. unsigned char eof;
  75. unsigned char at_sm;
  76. unsigned char last_block_valid;
  77. u32 last_block_visited;
  78. int drv_block; /* The block where the drive head is */
  79. int drv_file;
  80. };
  81. #define ST_NBR_PARTITIONS 4
  82. /* The tape drive descriptor */
  83. struct scsi_tape {
  84. struct scsi_driver *driver;
  85. struct scsi_device *device;
  86. struct mutex lock; /* For serialization */
  87. struct completion wait; /* For SCSI commands */
  88. struct st_buffer *buffer;
  89. /* Drive characteristics */
  90. unsigned char omit_blklims;
  91. unsigned char do_auto_lock;
  92. unsigned char can_bsr;
  93. unsigned char can_partitions;
  94. unsigned char two_fm;
  95. unsigned char fast_mteom;
  96. unsigned char immediate;
  97. unsigned char restr_dma;
  98. unsigned char scsi2_logical;
  99. unsigned char default_drvbuffer; /* 0xff = don't touch, value 3 bits */
  100. unsigned char cln_mode; /* 0 = none, otherwise sense byte nbr */
  101. unsigned char cln_sense_value;
  102. unsigned char cln_sense_mask;
  103. unsigned char use_pf; /* Set Page Format bit in all mode selects? */
  104. unsigned char try_dio; /* try direct i/o in general? */
  105. unsigned char try_dio_now; /* try direct i/o before next close? */
  106. unsigned char c_algo; /* compression algorithm */
  107. unsigned char pos_unknown; /* after reset position unknown */
  108. unsigned char sili; /* use SILI when reading in variable b mode */
  109. int tape_type;
  110. int long_timeout; /* timeout for commands known to take long time */
  111. unsigned long max_pfn; /* the maximum page number reachable by the HBA */
  112. /* Mode characteristics */
  113. struct st_modedef modes[ST_NBR_MODES];
  114. int current_mode;
  115. /* Status variables */
  116. int partition;
  117. int new_partition;
  118. int nbr_partitions; /* zero until partition support enabled */
  119. struct st_partstat ps[ST_NBR_PARTITIONS];
  120. unsigned char dirty;
  121. unsigned char ready;
  122. unsigned char write_prot;
  123. unsigned char drv_write_prot;
  124. unsigned char in_use;
  125. unsigned char blksize_changed;
  126. unsigned char density_changed;
  127. unsigned char compression_changed;
  128. unsigned char drv_buffer;
  129. unsigned char density;
  130. unsigned char door_locked;
  131. unsigned char autorew_dev; /* auto-rewind device */
  132. unsigned char rew_at_close; /* rewind necessary at close */
  133. unsigned char inited;
  134. unsigned char cleaning_req; /* cleaning requested? */
  135. int block_size;
  136. int min_block;
  137. int max_block;
  138. int recover_count; /* From tape opening */
  139. int recover_reg; /* From last status call */
  140. #if DEBUG
  141. unsigned char write_pending;
  142. int nbr_finished;
  143. int nbr_waits;
  144. int nbr_requests;
  145. int nbr_dio;
  146. int nbr_pages;
  147. unsigned char last_cmnd[6];
  148. unsigned char last_sense[16];
  149. #endif
  150. struct gendisk *disk;
  151. struct kref kref;
  152. };
  153. /* Bit masks for use_pf */
  154. #define USE_PF 1
  155. #define PF_TESTED 2
  156. /* Values of eof */
  157. #define ST_NOEOF 0
  158. #define ST_FM_HIT 1
  159. #define ST_FM 2
  160. #define ST_EOM_OK 3
  161. #define ST_EOM_ERROR 4
  162. #define ST_EOD_1 5
  163. #define ST_EOD_2 6
  164. #define ST_EOD 7
  165. /* EOD hit while reading => ST_EOD_1 => return zero => ST_EOD_2 =>
  166. return zero => ST_EOD, return ENOSPC */
  167. /* When writing: ST_EOM_OK == early warning found, write OK
  168. ST_EOD_1 == allow trying new write after early warning
  169. ST_EOM_ERROR == early warning found, not able to write all */
  170. /* Values of rw */
  171. #define ST_IDLE 0
  172. #define ST_READING 1
  173. #define ST_WRITING 2
  174. /* Values of ready state */
  175. #define ST_READY 0
  176. #define ST_NOT_READY 1
  177. #define ST_NO_TAPE 2
  178. /* Values for door lock state */
  179. #define ST_UNLOCKED 0
  180. #define ST_LOCKED_EXPLICIT 1
  181. #define ST_LOCKED_AUTO 2
  182. #define ST_LOCK_FAILS 3
  183. /* Positioning SCSI-commands for Tandberg, etc. drives */
  184. #define QFA_REQUEST_BLOCK 0x02
  185. #define QFA_SEEK_BLOCK 0x0c
  186. /* Setting the binary options */
  187. #define ST_DONT_TOUCH 0
  188. #define ST_NO 1
  189. #define ST_YES 2
  190. #define EXTENDED_SENSE_START 18
  191. /* Masks for some conditions in the sense data */
  192. #define SENSE_FMK 0x80
  193. #define SENSE_EOM 0x40
  194. #define SENSE_ILI 0x20
  195. #endif