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