tape.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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, 2009
  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 mutex to serialize tape commands. */
  189. struct mutex mutex;
  190. /* Device discipline information. */
  191. struct tape_discipline * discipline;
  192. void * discdata;
  193. /* Generic status flags */
  194. long tape_generic_status;
  195. /* Device state information. */
  196. wait_queue_head_t state_change_wq;
  197. enum tape_state tape_state;
  198. enum tape_medium_state medium_state;
  199. unsigned char * modeset_byte;
  200. /* Reference count. */
  201. atomic_t ref_count;
  202. /* Request queue. */
  203. struct list_head req_queue;
  204. /* Request wait queue. */
  205. wait_queue_head_t wait_queue;
  206. /* Each tape device has (currently) two minor numbers. */
  207. int first_minor;
  208. /* Number of tapemarks required for correct termination. */
  209. int required_tapemarks;
  210. /* Block ID of the BOF */
  211. unsigned int bof;
  212. /* Character device frontend data */
  213. struct tape_char_data char_data;
  214. #ifdef CONFIG_S390_TAPE_BLOCK
  215. /* Block dev frontend data */
  216. struct tape_blk_data blk_data;
  217. #endif
  218. /* Function to start or stop the next request later. */
  219. struct delayed_work tape_dnr;
  220. /* Timer for long busy */
  221. struct timer_list lb_timeout;
  222. };
  223. /* Externals from tape_core.c */
  224. extern struct tape_request *tape_alloc_request(int cplength, int datasize);
  225. extern void tape_free_request(struct tape_request *);
  226. extern int tape_do_io(struct tape_device *, struct tape_request *);
  227. extern int tape_do_io_async(struct tape_device *, struct tape_request *);
  228. extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
  229. extern int tape_cancel_io(struct tape_device *, struct tape_request *);
  230. void tape_hotplug_event(struct tape_device *, int major, int action);
  231. static inline int
  232. tape_do_io_free(struct tape_device *device, struct tape_request *request)
  233. {
  234. int rc;
  235. rc = tape_do_io(device, request);
  236. tape_free_request(request);
  237. return rc;
  238. }
  239. static inline void
  240. tape_do_io_async_free(struct tape_device *device, struct tape_request *request)
  241. {
  242. request->callback = (void *) tape_free_request;
  243. request->callback_data = NULL;
  244. tape_do_io_async(device, request);
  245. }
  246. extern int tape_oper_handler(int irq, int status);
  247. extern void tape_noper_handler(int irq, int status);
  248. extern int tape_open(struct tape_device *);
  249. extern int tape_release(struct tape_device *);
  250. extern int tape_mtop(struct tape_device *, int, int);
  251. extern void tape_state_set(struct tape_device *, enum tape_state);
  252. extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
  253. extern int tape_generic_offline(struct ccw_device *);
  254. extern int tape_generic_pm_suspend(struct ccw_device *);
  255. /* Externals from tape_devmap.c */
  256. extern int tape_generic_probe(struct ccw_device *);
  257. extern void tape_generic_remove(struct ccw_device *);
  258. extern struct tape_device *tape_find_device(int devindex);
  259. extern struct tape_device *tape_get_device(struct tape_device *);
  260. extern void tape_put_device(struct tape_device *);
  261. /* Externals from tape_char.c */
  262. extern int tapechar_init(void);
  263. extern void tapechar_exit(void);
  264. extern int tapechar_setup_device(struct tape_device *);
  265. extern void tapechar_cleanup_device(struct tape_device *);
  266. /* Externals from tape_block.c */
  267. #ifdef CONFIG_S390_TAPE_BLOCK
  268. extern int tapeblock_init (void);
  269. extern void tapeblock_exit(void);
  270. extern int tapeblock_setup_device(struct tape_device *);
  271. extern void tapeblock_cleanup_device(struct tape_device *);
  272. #else
  273. static inline int tapeblock_init (void) {return 0;}
  274. static inline void tapeblock_exit (void) {;}
  275. static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
  276. static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
  277. #endif
  278. /* tape initialisation functions */
  279. #ifdef CONFIG_PROC_FS
  280. extern void tape_proc_init (void);
  281. extern void tape_proc_cleanup (void);
  282. #else
  283. static inline void tape_proc_init (void) {;}
  284. static inline void tape_proc_cleanup (void) {;}
  285. #endif
  286. /* a function for dumping device sense info */
  287. extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
  288. struct irb *);
  289. /* functions for handling the status of a device */
  290. extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
  291. /* The debug area */
  292. extern debug_info_t *TAPE_DBF_AREA;
  293. /* functions for building ccws */
  294. static inline struct ccw1 *
  295. tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  296. {
  297. ccw->cmd_code = cmd_code;
  298. ccw->flags = CCW_FLAG_CC;
  299. ccw->count = memsize;
  300. ccw->cda = (__u32)(addr_t) cda;
  301. return ccw + 1;
  302. }
  303. static inline struct ccw1 *
  304. tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
  305. {
  306. ccw->cmd_code = cmd_code;
  307. ccw->flags = 0;
  308. ccw->count = memsize;
  309. ccw->cda = (__u32)(addr_t) cda;
  310. return ccw + 1;
  311. }
  312. static inline struct ccw1 *
  313. tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
  314. {
  315. ccw->cmd_code = cmd_code;
  316. ccw->flags = 0;
  317. ccw->count = 0;
  318. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  319. return ccw + 1;
  320. }
  321. static inline struct ccw1 *
  322. tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
  323. {
  324. while (count-- > 0) {
  325. ccw->cmd_code = cmd_code;
  326. ccw->flags = CCW_FLAG_CC;
  327. ccw->count = 0;
  328. ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
  329. ccw++;
  330. }
  331. return ccw;
  332. }
  333. static inline struct ccw1 *
  334. tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  335. {
  336. ccw->cmd_code = cmd_code;
  337. ccw->flags = CCW_FLAG_CC;
  338. idal_buffer_set_cda(idal, ccw);
  339. return ccw++;
  340. }
  341. static inline struct ccw1 *
  342. tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
  343. {
  344. ccw->cmd_code = cmd_code;
  345. ccw->flags = 0;
  346. idal_buffer_set_cda(idal, ccw);
  347. return ccw++;
  348. }
  349. /* Global vars */
  350. extern const char *tape_state_verbose[];
  351. extern const char *tape_op_verbose[];
  352. #endif /* for ifdef tape.h */