st.h 6.1 KB

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