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