2  *  drivers/s390/char/tape.h
 
   3  *    tape device driver for 3480/3490E/3590 tapes.
 
   5  *  S390 and zSeries version
 
   6  *    Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
 
   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>
 
  16 #include <asm/ccwdev.h>
 
  17 #include <asm/debug.h>
 
  18 #include <asm/idals.h>
 
  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>
 
  29  * Define DBF_LIKE_HELL for lots of messages in the debug feature.
 
  33 #define DBF_LH(level, str, ...) \
 
  35         debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
 
  38 #define DBF_LH(level, str, ...) do {} while(0)
 
  42  * macros s390 debug feature (dbf)
 
  44 #define DBF_EVENT(d_level, d_str...) \
 
  46         debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
 
  49 #define DBF_EXCEPTION(d_level, d_str...) \
 
  51         debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
 
  54 #define TAPE_VERSION_MAJOR 2
 
  55 #define TAPE_VERSION_MINOR 0
 
  56 #define TAPE_MAGIC "tape"
 
  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
 
  63 enum tape_medium_state {
 
  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 */
 
 102         TO_SIZE         /* #entries in tape_op_t */
 
 105 /* Forward declaration */
 
 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. */
 
 117 /* Tape CCW request */
 
 118 struct tape_request {
 
 119         struct list_head list;          /* list head for request queueing. */
 
 120         struct tape_device *device;     /* tape device of this request */
 
 121         struct ccw1 *cpaddr;            /* address of the channel program. */
 
 122         void *cpdata;                   /* pointer to ccw data. */
 
 123         enum tape_request_status status;/* status of this request */
 
 124         int options;                    /* options for execution. */
 
 125         int retries;                    /* retry counter for error recovery. */
 
 126         int rescnt;                     /* residual count from devstat. */
 
 128         /* Callback for delivering final status. */
 
 129         void (*callback)(struct tape_request *, void *);
 
 136 /* Function type for magnetic tape commands */
 
 137 typedef int (*tape_mtop_fn)(struct tape_device *, int);
 
 139 /* Size of the array containing the mtops for a discipline */
 
 140 #define TAPE_NR_MTOPS (MTMKPART+1)
 
 142 /* Tape Discipline */
 
 143 struct tape_discipline {
 
 144         struct module *owner;
 
 145         int  (*setup_device)(struct tape_device *);
 
 146         void (*cleanup_device)(struct tape_device *);
 
 147         int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
 
 148         struct tape_request *(*read_block)(struct tape_device *, size_t);
 
 149         struct tape_request *(*write_block)(struct tape_device *, size_t);
 
 150         void (*process_eov)(struct tape_device*);
 
 151 #ifdef CONFIG_S390_TAPE_BLOCK
 
 152         /* Block device stuff. */
 
 153         struct tape_request *(*bread)(struct tape_device *, struct request *);
 
 154         void (*check_locate)(struct tape_device *, struct tape_request *);
 
 155         void (*free_bread)(struct tape_request *);
 
 157         /* ioctl function for additional ioctls. */
 
 158         int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
 
 159         /* Array of tape commands with TAPE_NR_MTOPS entries */
 
 160         tape_mtop_fn *mtop_array;
 
 164  * The discipline irq function either returns an error code (<0) which
 
 165  * means that the request has failed with an error or one of the following:
 
 167 #define TAPE_IO_SUCCESS 0       /* request successful */
 
 168 #define TAPE_IO_PENDING 1       /* request still running */
 
 169 #define TAPE_IO_RETRY   2       /* retry to current request */
 
 170 #define TAPE_IO_STOP    3       /* stop the running request */
 
 172 /* Char Frontend Data */
 
 173 struct tape_char_data {
 
 174         struct idal_buffer *idal_buf;   /* idal buffer for user char data */
 
 175         int block_size;                 /*   of size block_size. */
 
 178 #ifdef CONFIG_S390_TAPE_BLOCK
 
 179 /* Block Frontend Data */
 
 182         /* Block device request queue. */
 
 183         request_queue_t *       request_queue;
 
 184         spinlock_t              request_queue_lock;
 
 186         /* Task to move entries from block request to CCS request queue. */
 
 187         struct work_struct      requeue_task;
 
 188         atomic_t                requeue_scheduled;
 
 190         /* Current position on the tape. */
 
 193         struct gendisk *        disk;
 
 199         /* entry in tape_device_list */
 
 200         struct list_head                node;
 
 203         struct ccw_device *             cdev;
 
 204         struct tape_class_device *      nt;
 
 205         struct tape_class_device *      rt;
 
 207         /* Device discipline information. */
 
 208         struct tape_discipline *        discipline;
 
 211         /* Generic status flags */
 
 212         long                            tape_generic_status;
 
 214         /* Device state information. */
 
 215         wait_queue_head_t               state_change_wq;
 
 216         enum tape_state                 tape_state;
 
 217         enum tape_medium_state          medium_state;
 
 218         unsigned char *                 modeset_byte;
 
 220         /* Reference count. */
 
 224         struct list_head                req_queue;
 
 226         /* Each tape device has (currently) two minor numbers. */
 
 229         /* Number of tapemarks required for correct termination. */
 
 230         int                             required_tapemarks;
 
 232         /* Block ID of the BOF */
 
 235         /* Character device frontend data */
 
 236         struct tape_char_data           char_data;
 
 237 #ifdef CONFIG_S390_TAPE_BLOCK
 
 238         /* Block dev frontend data */
 
 239         struct tape_blk_data            blk_data;
 
 242         /* Function to start or stop the next request later. */
 
 243         struct work_struct              tape_dnr;
 
 246 /* Externals from tape_core.c */
 
 247 extern struct tape_request *tape_alloc_request(int cplength, int datasize);
 
 248 extern void tape_free_request(struct tape_request *);
 
 249 extern int tape_do_io(struct tape_device *, struct tape_request *);
 
 250 extern int tape_do_io_async(struct tape_device *, struct tape_request *);
 
 251 extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
 
 252 extern int tape_cancel_io(struct tape_device *, struct tape_request *);
 
 253 void tape_hotplug_event(struct tape_device *, int major, int action);
 
 256 tape_do_io_free(struct tape_device *device, struct tape_request *request)
 
 260         rc = tape_do_io(device, request);
 
 261         tape_free_request(request);
 
 265 extern int tape_oper_handler(int irq, int status);
 
 266 extern void tape_noper_handler(int irq, int status);
 
 267 extern int tape_open(struct tape_device *);
 
 268 extern int tape_release(struct tape_device *);
 
 269 extern int tape_mtop(struct tape_device *, int, int);
 
 270 extern void tape_state_set(struct tape_device *, enum tape_state);
 
 272 extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
 
 273 extern int tape_generic_offline(struct tape_device *device);
 
 275 /* Externals from tape_devmap.c */
 
 276 extern int tape_generic_probe(struct ccw_device *);
 
 277 extern void tape_generic_remove(struct ccw_device *);
 
 279 extern struct tape_device *tape_get_device(int devindex);
 
 280 extern struct tape_device *tape_get_device_reference(struct tape_device *);
 
 281 extern struct tape_device *tape_put_device(struct tape_device *);
 
 283 /* Externals from tape_char.c */
 
 284 extern int tapechar_init(void);
 
 285 extern void tapechar_exit(void);
 
 286 extern int  tapechar_setup_device(struct tape_device *);
 
 287 extern void tapechar_cleanup_device(struct tape_device *);
 
 289 /* Externals from tape_block.c */
 
 290 #ifdef CONFIG_S390_TAPE_BLOCK
 
 291 extern int tapeblock_init (void);
 
 292 extern void tapeblock_exit(void);
 
 293 extern int tapeblock_setup_device(struct tape_device *);
 
 294 extern void tapeblock_cleanup_device(struct tape_device *);
 
 296 static inline int tapeblock_init (void) {return 0;}
 
 297 static inline void tapeblock_exit (void) {;}
 
 298 static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
 
 299 static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
 
 302 /* tape initialisation functions */
 
 303 #ifdef CONFIG_PROC_FS
 
 304 extern void tape_proc_init (void);
 
 305 extern void tape_proc_cleanup (void);
 
 307 static inline void tape_proc_init (void) {;}
 
 308 static inline void tape_proc_cleanup (void) {;}
 
 311 /* a function for dumping device sense info */
 
 312 extern void tape_dump_sense(struct tape_device *, struct tape_request *,
 
 314 extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
 
 317 /* functions for handling the status of a device */
 
 318 extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
 
 321 extern debug_info_t *TAPE_DBF_AREA;
 
 323 /* functions for building ccws */
 
 324 static inline struct ccw1 *
 
 325 tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
 
 327         ccw->cmd_code = cmd_code;
 
 328         ccw->flags = CCW_FLAG_CC;
 
 329         ccw->count = memsize;
 
 330         ccw->cda = (__u32)(addr_t) cda;
 
 334 static inline struct ccw1 *
 
 335 tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
 
 337         ccw->cmd_code = cmd_code;
 
 339         ccw->count = memsize;
 
 340         ccw->cda = (__u32)(addr_t) cda;
 
 344 static inline struct ccw1 *
 
 345 tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
 
 347         ccw->cmd_code = cmd_code;
 
 350         ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
 
 354 static inline struct ccw1 *
 
 355 tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
 
 357         while (count-- > 0) {
 
 358                 ccw->cmd_code = cmd_code;
 
 359                 ccw->flags = CCW_FLAG_CC;
 
 361                 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
 
 367 static inline struct ccw1 *
 
 368 tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
 
 370         ccw->cmd_code = cmd_code;
 
 371         ccw->flags    = CCW_FLAG_CC;
 
 372         idal_buffer_set_cda(idal, ccw);
 
 376 static inline struct ccw1 *
 
 377 tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
 
 379         ccw->cmd_code = cmd_code;
 
 381         idal_buffer_set_cda(idal, ccw);
 
 386 extern const char *tape_state_verbose[];
 
 387 extern const char *tape_op_verbose[];
 
 389 #endif /* for ifdef tape.h */