st.h 6.3 KB

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