tape.h 11 KB

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