tape.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * drivers/s390/char/tape.h
  3. * tape device driver for 3480/3490E/3590 tapes.
  4. *
  5. * S390 and zSeries version
  6. * Copyright IBM Corp. 2001,2006
  7. * Author(s): Carsten Otte <cotte@de.ibm.com>
  8. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  9. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  10. * Stefan Bader <shbader@de.ibm.com>
  11. */
  12. #ifndef _TAPE_H
  13. #define _TAPE_H
  14. #include <asm/ccwdev.h>
  15. #include <asm/debug.h>
  16. #include <asm/idals.h>
  17. #include <linux/blkdev.h>
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/mtio.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/workqueue.h>
  23. struct gendisk;
  24. /*
  25. * Define DBF_LIKE_HELL for lots of messages in the debug feature.
  26. */
  27. #define DBF_LIKE_HELL
  28. #ifdef DBF_LIKE_HELL
  29. #define DBF_LH(level, str, ...) \
  30. do { \
  31. debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
  32. } while (0)
  33. #else
  34. #define DBF_LH(level, str, ...) do {} while(0)
  35. #endif
  36. /*
  37. * macros s390 debug feature (dbf)
  38. */
  39. #define DBF_EVENT(d_level, d_str...) \
  40. do { \
  41. debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
  42. } while (0)
  43. #define DBF_EXCEPTION(d_level, d_str...) \
  44. do { \
  45. debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
  46. } while (0)
  47. #define TAPE_VERSION_MAJOR 2
  48. #define TAPE_VERSION_MINOR 0
  49. #define TAPE_MAGIC "tape"
  50. #define TAPE_MINORS_PER_DEV 2 /* two minors per device */
  51. #define TAPEBLOCK_HSEC_SIZE 2048
  52. #define TAPEBLOCK_HSEC_S2B 2
  53. #define TAPEBLOCK_RETRIES 5
  54. enum tape_medium_state {
  55. MS_UNKNOWN,
  56. MS_LOADED,
  57. MS_UNLOADED,
  58. MS_SIZE
  59. };
  60. enum tape_state {
  61. TS_UNUSED=0,
  62. TS_IN_USE,
  63. TS_BLKUSE,
  64. TS_INIT,
  65. TS_NOT_OPER,
  66. TS_SIZE
  67. };
  68. enum tape_op {
  69. TO_BLOCK, /* Block read */
  70. TO_BSB, /* Backward space block */
  71. TO_BSF, /* Backward space filemark */
  72. TO_DSE, /* Data security erase */
  73. TO_FSB, /* Forward space block */
  74. TO_FSF, /* Forward space filemark */
  75. TO_LBL, /* Locate block label */
  76. TO_NOP, /* No operation */
  77. TO_RBA, /* Read backward */
  78. TO_RBI, /* Read block information */
  79. TO_RFO, /* Read forward */
  80. TO_REW, /* Rewind tape */
  81. TO_RUN, /* Rewind and unload tape */
  82. TO_WRI, /* Write block */
  83. TO_WTM, /* Write tape mark */
  84. TO_MSEN, /* Medium sense */
  85. TO_LOAD, /* Load tape */
  86. TO_READ_CONFIG, /* Read configuration data */
  87. TO_READ_ATTMSG, /* Read attention message */
  88. TO_DIS, /* Tape display */
  89. TO_ASSIGN, /* Assign tape to channel path */
  90. TO_UNASSIGN, /* Unassign tape from channel path */
  91. TO_CRYPT_ON, /* Enable encrpytion */
  92. TO_CRYPT_OFF, /* Disable encrpytion */
  93. TO_KEKL_SET, /* Set KEK label */
  94. TO_KEKL_QUERY, /* Query KEK label */
  95. TO_RDC, /* Read device characteristics */
  96. TO_SIZE, /* #entries in tape_op_t */
  97. };
  98. /* Forward declaration */
  99. struct tape_device;
  100. /* tape_request->status can be: */
  101. enum tape_request_status {
  102. TAPE_REQUEST_INIT, /* request is ready to be processed */
  103. TAPE_REQUEST_QUEUED, /* request is queued to be processed */
  104. TAPE_REQUEST_IN_IO, /* request is currently in IO */
  105. TAPE_REQUEST_DONE, /* request is completed. */
  106. TAPE_REQUEST_CANCEL, /* request should be canceled. */
  107. TAPE_REQUEST_LONG_BUSY, /* request has to be restarted after long busy */
  108. };
  109. /* Tape CCW request */
  110. struct tape_request {
  111. struct list_head list; /* list head for request queueing. */
  112. struct tape_device *device; /* tape device of this request */
  113. struct ccw1 *cpaddr; /* address of the channel program. */
  114. void *cpdata; /* pointer to ccw data. */
  115. enum tape_request_status status;/* status of this request */
  116. int options; /* options for execution. */
  117. int retries; /* retry counter for error recovery. */
  118. int rescnt; /* residual count from devstat. */
  119. /* Callback for delivering final status. */
  120. void (*callback)(struct tape_request *, void *);
  121. void *callback_data;
  122. enum tape_op op;
  123. int rc;
  124. };
  125. /* Function type for magnetic tape commands */
  126. typedef int (*tape_mtop_fn)(struct tape_device *, int);
  127. /* Size of the array containing the mtops for a discipline */
  128. #define TAPE_NR_MTOPS (MTMKPART+1)
  129. /* Tape Discipline */
  130. struct tape_discipline {
  131. struct module *owner;
  132. int (*setup_device)(struct tape_device *);
  133. void (*cleanup_device)(struct tape_device *);
  134. int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
  135. struct tape_request *(*read_block)(struct tape_device *, size_t);
  136. struct tape_request *(*write_block)(struct tape_device *, size_t);
  137. void (*process_eov)(struct tape_device*);
  138. #ifdef CONFIG_S390_TAPE_BLOCK
  139. /* Block device stuff. */
  140. struct tape_request *(*bread)(struct tape_device *, struct request *);
  141. void (*check_locate)(struct tape_device *, struct tape_request *);
  142. void (*free_bread)(struct tape_request *);
  143. #endif
  144. /* ioctl function for additional ioctls. */
  145. int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
  146. /* Array of tape commands with TAPE_NR_MTOPS entries */
  147. tape_mtop_fn *mtop_array;
  148. };
  149. /*
  150. * The discipline irq function either returns an error code (<0) which
  151. * means that the request has failed with an error or one of the following:
  152. */
  153. #define TAPE_IO_SUCCESS 0 /* request successful */
  154. #define TAPE_IO_PENDING 1 /* request still running */
  155. #define TAPE_IO_RETRY 2 /* retry to current request */
  156. #define TAPE_IO_STOP 3 /* stop the running request */
  157. #define TAPE_IO_LONG_BUSY 4 /* delay the running request */
  158. /* Char Frontend Data */
  159. struct tape_char_data {
  160. struct idal_buffer *idal_buf; /* idal buffer for user char data */
  161. int block_size; /* of size block_size. */
  162. };
  163. #ifdef CONFIG_S390_TAPE_BLOCK
  164. /* Block Frontend Data */
  165. struct tape_blk_data
  166. {
  167. struct tape_device * device;
  168. /* Block device request queue. */
  169. struct request_queue * request_queue;
  170. spinlock_t request_queue_lock;
  171. /* Task to move entries from block request to CCS request queue. */
  172. struct work_struct requeue_task;
  173. atomic_t requeue_scheduled;
  174. /* Current position on the tape. */
  175. long block_position;
  176. int medium_changed;
  177. struct gendisk * disk;
  178. };
  179. #endif
  180. /* Tape Info */
  181. struct tape_device {
  182. /* entry in tape_device_list */
  183. struct list_head node;
  184. int cdev_id;
  185. struct ccw_device * cdev;
  186. struct tape_class_device * nt;
  187. struct tape_class_device * rt;
  188. /* Device discipline information. */
  189. struct tape_discipline * discipline;
  190. void * discdata;
  191. /* Generic status flags */
  192. long tape_generic_status;
  193. /* Device state information. */
  194. wait_queue_head_t state_change_wq;
  195. enum tape_state tape_state;
  196. enum tape_medium_state medium_state;
  197. unsigned char * modeset_byte;
  198. /* Reference count. */
  199. atomic_t ref_count;
  200. /* Request queue. */
  201. struct list_head req_queue;
  202. /* Request wait queue. */
  203. wait_queue_head_t wait_queue;
  204. /* Each tape device has (currently) two minor numbers. */
  205. int first_minor;
  206. /* Number of tapemarks required for correct termination. */
  207. int required_tapemarks;
  208. /* Block ID of the BOF */
  209. unsigned int bof;
  210. /* Character device frontend data */
  211. struct tape_char_data char_data;
  212. #ifdef CONFIG_S390_TAPE_BLOCK
  213. /* Block dev frontend data */
  214. struct tape_blk_data blk_data;
  215. #endif
  216. /* Function to start or stop the next request later. */
  217. struct delayed_work tape_dnr;
  218. /* Timer for long busy */
  219. struct timer_list lb_timeout;
  220. };
  221. /* Externals from tape_core.c */
  222. extern struct tape_request *tape_alloc_request(int cplength, int datasize);
  223. extern void tape_free_request(struct tape_request *);
  224. extern int tape_do_io(struct tape_device *, struct tape_request *);
  225. extern int tape_do_io_async(struct tape_device *, struct tape_request *);
  226. extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
  227. extern int tape_cancel_io(struct tape_device *, struct tape_request *);
  228. void tape_hotplug_event(struct tape_device *, int major, int action);
  229. static inline int
  230. tape_do_io_free(struct tape_device *device, struct tape_request *request)
  231. {
  232. int rc;
  233. rc = tape_do_io(device, request);
  234. tape_free_request(request);
  235. return rc;
  236. }
  237. extern int tape_oper_handler(int irq, int status);
  238. extern void tape_noper_handler(int irq, int status);
  239. extern int tape_open(struct tape_device *);
  240. extern int tape_release(struct tape_device *);
  241. extern int tape_mtop(struct tape_device *, int, int);
  242. extern void tape_state_set(struct tape_device *, enum tape_state);
  243. extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
  244. extern int tape_generic_offline(struct tape_device *device);
  245. /* Externals from tape_devmap.c */
  246. extern int tape_generic_probe(struct ccw_device *);
  247. extern void tape_generic_remove(struct ccw_device *);
  248. extern struct tape_device *tape_get_device(int devindex);
  249. extern struct tape_device *tape_get_device_reference(struct tape_device *);
  250. extern struct tape_device *tape_put_device(struct tape_device *);
  251. /* Externals from tape_char.c */
  252. extern int tapechar_init(void);
  253. extern void tapechar_exit(void);
  254. extern int tapechar_setup_device(struct tape_device *);
  255. extern void tapechar_cleanup_device(struct tape_device *);
  256. /* Externals from tape_block.c */
  257. #ifdef CONFIG_S390_TAPE_BLOCK
  258. extern int tapeblock_init (void);
  259. extern void tapeblock_exit(void);
  260. extern int tapeblock_setup_device(struct tape_device *);
  261. extern void tapeblock_cleanup_device(struct tape_device *);
  262. #else
  263. static inline int tapeblock_init (void) {return 0;}
  264. static inline void tapeblock_exit (void) {;}
  265. static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
  266. static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
  267. #endif
  268. /* tape initialisation functions */
  269. #ifdef CONFIG_PROC_FS
  270. extern void tape_proc_init (void);
  271. extern void tape_proc_cleanup (void);
  272. #else
  273. static inline void tape_proc_init (void) {;}
  274. static inline void tape_proc_cleanup (void) {;}
  275. #endif
  276. /* a function for dumping device sense info */
  277. extern void tape_dump_sense(struct tape_device *, struct tape_request *,
  278. struct irb *);
  279. extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
  280. struct irb *);
  281. /* functions for handling the status of a device */
  282. extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
  283. /* The debug area */
  284. extern debug_info_t *TAPE_DBF_AREA;
  285. /* functions for building ccws */
  286. static inline struct ccw1 *
  287. tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  288. {
  289. ccw->cmd_code = cmd_code;
  290. ccw->flags = CCW_FLAG_CC;
  291. ccw->count = memsize;
  292. ccw->cda = (__u32)(addr_t) cda;
  293. return ccw + 1;
  294. }
  295. static inline struct ccw1 *
  296. tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  297. {
  298. ccw->cmd_code = cmd_code;
  299. ccw->flags = 0;
  300. ccw->count = memsize;
  301. ccw->cda = (__u32)(addr_t) cda;
  302. return ccw + 1;
  303. }
  304. static inline struct ccw1 *
  305. tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
  306. {
  307. ccw->cmd_code = cmd_code;
  308. ccw->flags = 0;
  309. ccw->count = 0;
  310. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  311. return ccw + 1;
  312. }
  313. static inline struct ccw1 *
  314. tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
  315. {
  316. while (count-- > 0) {
  317. ccw->cmd_code = cmd_code;
  318. ccw->flags = CCW_FLAG_CC;
  319. ccw->count = 0;
  320. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  321. ccw++;
  322. }
  323. return ccw;
  324. }
  325. static inline struct ccw1 *
  326. tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  327. {
  328. ccw->cmd_code = cmd_code;
  329. ccw->flags = CCW_FLAG_CC;
  330. idal_buffer_set_cda(idal, ccw);
  331. return ccw++;
  332. }
  333. static inline struct ccw1 *
  334. tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  335. {
  336. ccw->cmd_code = cmd_code;
  337. ccw->flags = 0;
  338. idal_buffer_set_cda(idal, ccw);
  339. return ccw++;
  340. }
  341. /* Global vars */
  342. extern const char *tape_state_verbose[];
  343. extern const char *tape_op_verbose[];
  344. #endif /* for ifdef tape.h */