tape.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * tape device driver for 3480/3490E/3590 tapes.
  4. *
  5. * S390 and zSeries version
  6. * Copyright IBM Corp. 2001, 2009
  7. * Author(s): Carsten Otte <[email protected]>
  8. * Tuan Ngo-Anh <[email protected]>
  9. * Martin Schwidefsky <[email protected]>
  10. * Stefan Bader <[email protected]>
  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/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. struct timer_list timer; /* timer for std_assign_timeout(). */
  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. /* ioctl function for additional ioctls. */
  139. int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
  140. /* Array of tape commands with TAPE_NR_MTOPS entries */
  141. tape_mtop_fn *mtop_array;
  142. };
  143. /*
  144. * The discipline irq function either returns an error code (<0) which
  145. * means that the request has failed with an error or one of the following:
  146. */
  147. #define TAPE_IO_SUCCESS 0 /* request successful */
  148. #define TAPE_IO_PENDING 1 /* request still running */
  149. #define TAPE_IO_RETRY 2 /* retry to current request */
  150. #define TAPE_IO_STOP 3 /* stop the running request */
  151. #define TAPE_IO_LONG_BUSY 4 /* delay 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. /* Tape Info */
  158. struct tape_device {
  159. /* entry in tape_device_list */
  160. struct list_head node;
  161. int cdev_id;
  162. struct ccw_device * cdev;
  163. struct tape_class_device * nt;
  164. struct tape_class_device * rt;
  165. /* Device mutex to serialize tape commands. */
  166. struct mutex mutex;
  167. /* Device discipline information. */
  168. struct tape_discipline * discipline;
  169. void * discdata;
  170. /* Generic status flags */
  171. long tape_generic_status;
  172. /* Device state information. */
  173. wait_queue_head_t state_change_wq;
  174. enum tape_state tape_state;
  175. enum tape_medium_state medium_state;
  176. unsigned char * modeset_byte;
  177. /* Reference count. */
  178. atomic_t ref_count;
  179. /* Request queue. */
  180. struct list_head req_queue;
  181. /* Request wait queue. */
  182. wait_queue_head_t wait_queue;
  183. /* Each tape device has (currently) two minor numbers. */
  184. int first_minor;
  185. /* Number of tapemarks required for correct termination. */
  186. int required_tapemarks;
  187. /* Block ID of the BOF */
  188. unsigned int bof;
  189. /* Character device frontend data */
  190. struct tape_char_data char_data;
  191. /* Function to start or stop the next request later. */
  192. struct delayed_work tape_dnr;
  193. /* Timer for long busy */
  194. struct timer_list lb_timeout;
  195. };
  196. /* Externals from tape_core.c */
  197. extern struct tape_request *tape_alloc_request(int cplength, int datasize);
  198. extern void tape_free_request(struct tape_request *);
  199. extern int tape_do_io(struct tape_device *, struct tape_request *);
  200. extern int tape_do_io_async(struct tape_device *, struct tape_request *);
  201. extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
  202. extern int tape_cancel_io(struct tape_device *, struct tape_request *);
  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_open(struct tape_device *);
  219. extern int tape_release(struct tape_device *);
  220. extern int tape_mtop(struct tape_device *, int, int);
  221. extern void tape_state_set(struct tape_device *, enum tape_state);
  222. extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
  223. extern int tape_generic_offline(struct ccw_device *);
  224. /* Externals from tape_devmap.c */
  225. extern int tape_generic_probe(struct ccw_device *);
  226. extern void tape_generic_remove(struct ccw_device *);
  227. extern struct tape_device *tape_find_device(int devindex);
  228. extern struct tape_device *tape_get_device(struct tape_device *);
  229. extern void tape_put_device(struct tape_device *);
  230. /* Externals from tape_char.c */
  231. extern int tapechar_init(void);
  232. extern void tapechar_exit(void);
  233. extern int tapechar_setup_device(struct tape_device *);
  234. extern void tapechar_cleanup_device(struct tape_device *);
  235. /* tape initialisation functions */
  236. #ifdef CONFIG_PROC_FS
  237. extern void tape_proc_init (void);
  238. extern void tape_proc_cleanup (void);
  239. #else
  240. static inline void tape_proc_init (void) {;}
  241. static inline void tape_proc_cleanup (void) {;}
  242. #endif
  243. /* a function for dumping device sense info */
  244. extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
  245. struct irb *);
  246. /* functions for handling the status of a device */
  247. extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
  248. /* The debug area */
  249. extern debug_info_t *TAPE_DBF_AREA;
  250. /* functions for building ccws */
  251. static inline struct ccw1 *
  252. tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  253. {
  254. ccw->cmd_code = cmd_code;
  255. ccw->flags = CCW_FLAG_CC;
  256. ccw->count = memsize;
  257. ccw->cda = (__u32)(addr_t) cda;
  258. return ccw + 1;
  259. }
  260. static inline struct ccw1 *
  261. tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  262. {
  263. ccw->cmd_code = cmd_code;
  264. ccw->flags = 0;
  265. ccw->count = memsize;
  266. ccw->cda = (__u32)(addr_t) cda;
  267. return ccw + 1;
  268. }
  269. static inline struct ccw1 *
  270. tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
  271. {
  272. ccw->cmd_code = cmd_code;
  273. ccw->flags = 0;
  274. ccw->count = 0;
  275. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  276. return ccw + 1;
  277. }
  278. static inline struct ccw1 *
  279. tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
  280. {
  281. while (count-- > 0) {
  282. ccw->cmd_code = cmd_code;
  283. ccw->flags = CCW_FLAG_CC;
  284. ccw->count = 0;
  285. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  286. ccw++;
  287. }
  288. return ccw;
  289. }
  290. static inline struct ccw1 *
  291. tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  292. {
  293. ccw->cmd_code = cmd_code;
  294. ccw->flags = CCW_FLAG_CC;
  295. idal_buffer_set_cda(idal, ccw);
  296. return ccw++;
  297. }
  298. static inline struct ccw1 *
  299. tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  300. {
  301. ccw->cmd_code = cmd_code;
  302. ccw->flags = 0;
  303. idal_buffer_set_cda(idal, ccw);
  304. return ccw++;
  305. }
  306. /* Global vars */
  307. extern const char *tape_state_verbose[];
  308. extern const char *tape_op_verbose[];
  309. #endif /* for ifdef tape.h */