tape.h 10 KB

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