st.h 5.9 KB

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