0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
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
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
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
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,
0080 TO_BSB,
0081 TO_BSF,
0082 TO_DSE,
0083 TO_FSB,
0084 TO_FSF,
0085 TO_LBL,
0086 TO_NOP,
0087 TO_RBA,
0088 TO_RBI,
0089 TO_RFO,
0090 TO_REW,
0091 TO_RUN,
0092 TO_WRI,
0093 TO_WTM,
0094 TO_MSEN,
0095 TO_LOAD,
0096 TO_READ_CONFIG,
0097 TO_READ_ATTMSG,
0098 TO_DIS,
0099 TO_ASSIGN,
0100 TO_UNASSIGN,
0101 TO_CRYPT_ON,
0102 TO_CRYPT_OFF,
0103 TO_KEKL_SET,
0104 TO_KEKL_QUERY,
0105 TO_RDC,
0106 TO_SIZE,
0107 };
0108
0109
0110 struct tape_device;
0111
0112
0113 enum tape_request_status {
0114 TAPE_REQUEST_INIT,
0115 TAPE_REQUEST_QUEUED,
0116 TAPE_REQUEST_IN_IO,
0117 TAPE_REQUEST_DONE,
0118 TAPE_REQUEST_CANCEL,
0119 TAPE_REQUEST_LONG_BUSY,
0120 };
0121
0122
0123 struct tape_request {
0124 struct list_head list;
0125 struct tape_device *device;
0126 struct ccw1 *cpaddr;
0127 void *cpdata;
0128 enum tape_request_status status;
0129 int options;
0130 int retries;
0131 int rescnt;
0132 struct timer_list timer;
0133
0134
0135 void (*callback)(struct tape_request *, void *);
0136 void *callback_data;
0137
0138 enum tape_op op;
0139 int rc;
0140 };
0141
0142
0143 typedef int (*tape_mtop_fn)(struct tape_device *, int);
0144
0145
0146 #define TAPE_NR_MTOPS (MTMKPART+1)
0147
0148
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
0158 int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
0159
0160 tape_mtop_fn *mtop_array;
0161 };
0162
0163
0164
0165
0166
0167 #define TAPE_IO_SUCCESS 0
0168 #define TAPE_IO_PENDING 1
0169 #define TAPE_IO_RETRY 2
0170 #define TAPE_IO_STOP 3
0171 #define TAPE_IO_LONG_BUSY 4
0172
0173
0174 struct tape_char_data {
0175 struct idal_buffer *idal_buf;
0176 int block_size;
0177 };
0178
0179
0180 struct tape_device {
0181
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
0190 struct mutex mutex;
0191
0192
0193 struct tape_discipline * discipline;
0194 void * discdata;
0195
0196
0197 long tape_generic_status;
0198
0199
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
0206 atomic_t ref_count;
0207
0208
0209 struct list_head req_queue;
0210
0211
0212 wait_queue_head_t wait_queue;
0213
0214
0215 int first_minor;
0216
0217
0218 int required_tapemarks;
0219
0220
0221 unsigned int bof;
0222
0223
0224 struct tape_char_data char_data;
0225
0226
0227 struct delayed_work tape_dnr;
0228
0229
0230 struct timer_list lb_timeout;
0231
0232 };
0233
0234
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
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
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
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
0292 extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
0293 struct irb *);
0294
0295
0296 extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
0297
0298
0299 extern debug_info_t *TAPE_DBF_AREA;
0300
0301
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
0364 extern const char *tape_state_verbose[];
0365 extern const char *tape_op_verbose[];
0366
0367 #endif