tape.h 10 KB

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