Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *    tape device driver for 3480/3490E/3590 tapes.
0004  *
0005  *  S390 and zSeries version
0006  *    Copyright IBM Corp. 2001, 2009
0007  *    Author(s): Carsten Otte <cotte@de.ibm.com>
0008  *       Tuan Ngo-Anh <ngoanh@de.ibm.com>
0009  *       Martin Schwidefsky <schwidefsky@de.ibm.com>
0010  *       Stefan Bader <shbader@de.ibm.com>
0011  */
0012 
0013 #ifndef _TAPE_H
0014 #define _TAPE_H
0015 
0016 #include <asm/ccwdev.h>
0017 #include <asm/debug.h>
0018 #include <asm/idals.h>
0019 #include <linux/kernel.h>
0020 #include <linux/module.h>
0021 #include <linux/mtio.h>
0022 #include <linux/interrupt.h>
0023 #include <linux/workqueue.h>
0024 
0025 struct gendisk;
0026 
0027 /*
0028  * Define DBF_LIKE_HELL for lots of messages in the debug feature.
0029  */
0030 #define DBF_LIKE_HELL
0031 #ifdef  DBF_LIKE_HELL
0032 #define DBF_LH(level, str, ...) \
0033 do { \
0034     debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
0035 } while (0)
0036 #else
0037 #define DBF_LH(level, str, ...) do {} while(0)
0038 #endif
0039 
0040 /*
0041  * macros s390 debug feature (dbf)
0042  */
0043 #define DBF_EVENT(d_level, d_str...) \
0044 do { \
0045     debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
0046 } while (0)
0047 
0048 #define DBF_EXCEPTION(d_level, d_str...) \
0049 do { \
0050     debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
0051 } while (0)
0052 
0053 #define TAPE_VERSION_MAJOR 2
0054 #define TAPE_VERSION_MINOR 0
0055 #define TAPE_MAGIC "tape"
0056 
0057 #define TAPE_MINORS_PER_DEV 2       /* two minors per device */
0058 #define TAPEBLOCK_HSEC_SIZE 2048
0059 #define TAPEBLOCK_HSEC_S2B  2
0060 #define TAPEBLOCK_RETRIES   5
0061 
0062 enum tape_medium_state {
0063     MS_UNKNOWN,
0064     MS_LOADED,
0065     MS_UNLOADED,
0066     MS_SIZE
0067 };
0068 
0069 enum tape_state {
0070     TS_UNUSED=0,
0071     TS_IN_USE,
0072     TS_BLKUSE,
0073     TS_INIT,
0074     TS_NOT_OPER,
0075     TS_SIZE
0076 };
0077 
0078 enum tape_op {
0079     TO_BLOCK,   /* Block read */
0080     TO_BSB,     /* Backward space block */
0081     TO_BSF,     /* Backward space filemark */
0082     TO_DSE,     /* Data security erase */
0083     TO_FSB,     /* Forward space block */
0084     TO_FSF,     /* Forward space filemark */
0085     TO_LBL,     /* Locate block label */
0086     TO_NOP,     /* No operation */
0087     TO_RBA,     /* Read backward */
0088     TO_RBI,     /* Read block information */
0089     TO_RFO,     /* Read forward */
0090     TO_REW,     /* Rewind tape */
0091     TO_RUN,     /* Rewind and unload tape */
0092     TO_WRI,     /* Write block */
0093     TO_WTM,     /* Write tape mark */
0094     TO_MSEN,    /* Medium sense */
0095     TO_LOAD,    /* Load tape */
0096     TO_READ_CONFIG, /* Read configuration data */
0097     TO_READ_ATTMSG, /* Read attention message */
0098     TO_DIS,     /* Tape display */
0099     TO_ASSIGN,  /* Assign tape to channel path */
0100     TO_UNASSIGN,    /* Unassign tape from channel path */
0101     TO_CRYPT_ON,    /* Enable encrpytion */
0102     TO_CRYPT_OFF,   /* Disable encrpytion */
0103     TO_KEKL_SET,    /* Set KEK label */
0104     TO_KEKL_QUERY,  /* Query KEK label */
0105     TO_RDC,     /* Read device characteristics */
0106     TO_SIZE,    /* #entries in tape_op_t */
0107 };
0108 
0109 /* Forward declaration */
0110 struct tape_device;
0111 
0112 /* tape_request->status can be: */
0113 enum tape_request_status {
0114     TAPE_REQUEST_INIT,  /* request is ready to be processed */
0115     TAPE_REQUEST_QUEUED,    /* request is queued to be processed */
0116     TAPE_REQUEST_IN_IO, /* request is currently in IO */
0117     TAPE_REQUEST_DONE,  /* request is completed. */
0118     TAPE_REQUEST_CANCEL,    /* request should be canceled. */
0119     TAPE_REQUEST_LONG_BUSY, /* request has to be restarted after long busy */
0120 };
0121 
0122 /* Tape CCW request */
0123 struct tape_request {
0124     struct list_head list;      /* list head for request queueing. */
0125     struct tape_device *device; /* tape device of this request */
0126     struct ccw1 *cpaddr;        /* address of the channel program. */
0127     void *cpdata;           /* pointer to ccw data. */
0128     enum tape_request_status status;/* status of this request */
0129     int options;            /* options for execution. */
0130     int retries;            /* retry counter for error recovery. */
0131     int rescnt;         /* residual count from devstat. */
0132     struct timer_list timer;    /* timer for std_assign_timeout(). */
0133 
0134     /* Callback for delivering final status. */
0135     void (*callback)(struct tape_request *, void *);
0136     void *callback_data;
0137 
0138     enum tape_op op;
0139     int rc;
0140 };
0141 
0142 /* Function type for magnetic tape commands */
0143 typedef int (*tape_mtop_fn)(struct tape_device *, int);
0144 
0145 /* Size of the array containing the mtops for a discipline */
0146 #define TAPE_NR_MTOPS (MTMKPART+1)
0147 
0148 /* Tape Discipline */
0149 struct tape_discipline {
0150     struct module *owner;
0151     int  (*setup_device)(struct tape_device *);
0152     void (*cleanup_device)(struct tape_device *);
0153     int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
0154     struct tape_request *(*read_block)(struct tape_device *, size_t);
0155     struct tape_request *(*write_block)(struct tape_device *, size_t);
0156     void (*process_eov)(struct tape_device*);
0157     /* ioctl function for additional ioctls. */
0158     int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
0159     /* Array of tape commands with TAPE_NR_MTOPS entries */
0160     tape_mtop_fn *mtop_array;
0161 };
0162 
0163 /*
0164  * The discipline irq function either returns an error code (<0) which
0165  * means that the request has failed with an error or one of the following:
0166  */
0167 #define TAPE_IO_SUCCESS     0   /* request successful */
0168 #define TAPE_IO_PENDING     1   /* request still running */
0169 #define TAPE_IO_RETRY       2   /* retry to current request */
0170 #define TAPE_IO_STOP        3   /* stop the running request */
0171 #define TAPE_IO_LONG_BUSY   4   /* delay the running request */
0172 
0173 /* Char Frontend Data */
0174 struct tape_char_data {
0175     struct idal_buffer *idal_buf;   /* idal buffer for user char data */
0176     int block_size;         /*   of size block_size. */
0177 };
0178 
0179 /* Tape Info */
0180 struct tape_device {
0181     /* entry in tape_device_list */
0182     struct list_head        node;
0183 
0184     int             cdev_id;
0185     struct ccw_device *     cdev;
0186     struct tape_class_device *  nt;
0187     struct tape_class_device *  rt;
0188 
0189     /* Device mutex to serialize tape commands. */
0190     struct mutex            mutex;
0191 
0192     /* Device discipline information. */
0193     struct tape_discipline *    discipline;
0194     void *              discdata;
0195 
0196     /* Generic status flags */
0197     long                tape_generic_status;
0198 
0199     /* Device state information. */
0200     wait_queue_head_t       state_change_wq;
0201     enum tape_state         tape_state;
0202     enum tape_medium_state      medium_state;
0203     unsigned char *         modeset_byte;
0204 
0205     /* Reference count. */
0206     atomic_t            ref_count;
0207 
0208     /* Request queue. */
0209     struct list_head        req_queue;
0210 
0211     /* Request wait queue. */
0212     wait_queue_head_t       wait_queue;
0213 
0214     /* Each tape device has (currently) two minor numbers. */
0215     int             first_minor;
0216 
0217     /* Number of tapemarks required for correct termination. */
0218     int             required_tapemarks;
0219 
0220     /* Block ID of the BOF */
0221     unsigned int            bof;
0222 
0223     /* Character device frontend data */
0224     struct tape_char_data       char_data;
0225 
0226     /* Function to start or stop the next request later. */
0227     struct delayed_work     tape_dnr;
0228 
0229     /* Timer for long busy */
0230     struct timer_list       lb_timeout;
0231 
0232 };
0233 
0234 /* Externals from tape_core.c */
0235 extern struct tape_request *tape_alloc_request(int cplength, int datasize);
0236 extern void tape_free_request(struct tape_request *);
0237 extern int tape_do_io(struct tape_device *, struct tape_request *);
0238 extern int tape_do_io_async(struct tape_device *, struct tape_request *);
0239 extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
0240 extern int tape_cancel_io(struct tape_device *, struct tape_request *);
0241 
0242 static inline int
0243 tape_do_io_free(struct tape_device *device, struct tape_request *request)
0244 {
0245     int rc;
0246 
0247     rc = tape_do_io(device, request);
0248     tape_free_request(request);
0249     return rc;
0250 }
0251 
0252 static inline void
0253 tape_do_io_async_free(struct tape_device *device, struct tape_request *request)
0254 {
0255     request->callback = (void *) tape_free_request;
0256     request->callback_data = NULL;
0257     tape_do_io_async(device, request);
0258 }
0259 
0260 extern int tape_open(struct tape_device *);
0261 extern int tape_release(struct tape_device *);
0262 extern int tape_mtop(struct tape_device *, int, int);
0263 extern void tape_state_set(struct tape_device *, enum tape_state);
0264 
0265 extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
0266 extern int tape_generic_offline(struct ccw_device *);
0267 
0268 /* Externals from tape_devmap.c */
0269 extern int tape_generic_probe(struct ccw_device *);
0270 extern void tape_generic_remove(struct ccw_device *);
0271 
0272 extern struct tape_device *tape_find_device(int devindex);
0273 extern struct tape_device *tape_get_device(struct tape_device *);
0274 extern void tape_put_device(struct tape_device *);
0275 
0276 /* Externals from tape_char.c */
0277 extern int tapechar_init(void);
0278 extern void tapechar_exit(void);
0279 extern int  tapechar_setup_device(struct tape_device *);
0280 extern void tapechar_cleanup_device(struct tape_device *);
0281 
0282 /* tape initialisation functions */
0283 #ifdef CONFIG_PROC_FS
0284 extern void tape_proc_init (void);
0285 extern void tape_proc_cleanup (void);
0286 #else
0287 static inline void tape_proc_init (void) {;}
0288 static inline void tape_proc_cleanup (void) {;}
0289 #endif
0290 
0291 /* a function for dumping device sense info */
0292 extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
0293                 struct irb *);
0294 
0295 /* functions for handling the status of a device */
0296 extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
0297 
0298 /* The debug area */
0299 extern debug_info_t *TAPE_DBF_AREA;
0300 
0301 /* functions for building ccws */
0302 static inline struct ccw1 *
0303 tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
0304 {
0305     ccw->cmd_code = cmd_code;
0306     ccw->flags = CCW_FLAG_CC;
0307     ccw->count = memsize;
0308     ccw->cda = (__u32)(addr_t) cda;
0309     return ccw + 1;
0310 }
0311 
0312 static inline struct ccw1 *
0313 tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
0314 {
0315     ccw->cmd_code = cmd_code;
0316     ccw->flags = 0;
0317     ccw->count = memsize;
0318     ccw->cda = (__u32)(addr_t) cda;
0319     return ccw + 1;
0320 }
0321 
0322 static inline struct ccw1 *
0323 tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
0324 {
0325     ccw->cmd_code = cmd_code;
0326     ccw->flags = 0;
0327     ccw->count = 0;
0328     ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
0329     return ccw + 1;
0330 }
0331 
0332 static inline struct ccw1 *
0333 tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
0334 {
0335     while (count-- > 0) {
0336         ccw->cmd_code = cmd_code;
0337         ccw->flags = CCW_FLAG_CC;
0338         ccw->count = 0;
0339         ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
0340         ccw++;
0341     }
0342     return ccw;
0343 }
0344 
0345 static inline struct ccw1 *
0346 tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
0347 {
0348     ccw->cmd_code = cmd_code;
0349     ccw->flags    = CCW_FLAG_CC;
0350     idal_buffer_set_cda(idal, ccw);
0351     return ccw++;
0352 }
0353 
0354 static inline struct ccw1 *
0355 tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
0356 {
0357     ccw->cmd_code = cmd_code;
0358     ccw->flags    = 0;
0359     idal_buffer_set_cda(idal, ccw);
0360     return ccw++;
0361 }
0362 
0363 /* Global vars */
0364 extern const char *tape_state_verbose[];
0365 extern const char *tape_op_verbose[];
0366 
0367 #endif /* for ifdef tape.h */