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