diff options
Diffstat (limited to 'drivers/s390/char/tape.h')
-rw-r--r-- | drivers/s390/char/tape.h | 384 |
1 files changed, 384 insertions, 0 deletions
diff --git a/drivers/s390/char/tape.h b/drivers/s390/char/tape.h new file mode 100644 index 000000000000..d04e6c2c3cc1 --- /dev/null +++ b/drivers/s390/char/tape.h | |||
@@ -0,0 +1,384 @@ | |||
1 | /* | ||
2 | * drivers/s390/char/tape.h | ||
3 | * tape device driver for 3480/3490E/3590 tapes. | ||
4 | * | ||
5 | * S390 and zSeries version | ||
6 | * Copyright (C) 2001,2002 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 | */ | ||
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> | ||
18 | #include <linux/config.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> | ||
25 | |||
26 | struct gendisk; | ||
27 | |||
28 | /* | ||
29 | * Define DBF_LIKE_HELL for lots of messages in the debug feature. | ||
30 | */ | ||
31 | #define DBF_LIKE_HELL | ||
32 | #ifdef DBF_LIKE_HELL | ||
33 | #define DBF_LH(level, str, ...) \ | ||
34 | do { \ | ||
35 | debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \ | ||
36 | } while (0) | ||
37 | #else | ||
38 | #define DBF_LH(level, str, ...) do {} while(0) | ||
39 | #endif | ||
40 | |||
41 | /* | ||
42 | * macros s390 debug feature (dbf) | ||
43 | */ | ||
44 | #define DBF_EVENT(d_level, d_str...) \ | ||
45 | do { \ | ||
46 | debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \ | ||
47 | } while (0) | ||
48 | |||
49 | #define DBF_EXCEPTION(d_level, d_str...) \ | ||
50 | do { \ | ||
51 | debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \ | ||
52 | } while (0) | ||
53 | |||
54 | #define TAPE_VERSION_MAJOR 2 | ||
55 | #define TAPE_VERSION_MINOR 0 | ||
56 | #define TAPE_MAGIC "tape" | ||
57 | |||
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 | ||
62 | |||
63 | enum tape_medium_state { | ||
64 | MS_UNKNOWN, | ||
65 | MS_LOADED, | ||
66 | MS_UNLOADED, | ||
67 | MS_SIZE | ||
68 | }; | ||
69 | |||
70 | enum tape_state { | ||
71 | TS_UNUSED=0, | ||
72 | TS_IN_USE, | ||
73 | TS_BLKUSE, | ||
74 | TS_INIT, | ||
75 | TS_NOT_OPER, | ||
76 | TS_SIZE | ||
77 | }; | ||
78 | |||
79 | enum tape_op { | ||
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 */ | ||
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 | }; | ||
115 | |||
116 | /* Tape CCW request */ | ||
117 | struct tape_request { | ||
118 | struct list_head list; /* list head for request queueing. */ | ||
119 | struct tape_device *device; /* tape device of this request */ | ||
120 | struct ccw1 *cpaddr; /* address of the channel program. */ | ||
121 | void *cpdata; /* pointer to ccw data. */ | ||
122 | enum tape_request_status status;/* status of this request */ | ||
123 | int options; /* options for execution. */ | ||
124 | int retries; /* retry counter for error recovery. */ | ||
125 | int rescnt; /* residual count from devstat. */ | ||
126 | |||
127 | /* Callback for delivering final status. */ | ||
128 | void (*callback)(struct tape_request *, void *); | ||
129 | void *callback_data; | ||
130 | |||
131 | enum tape_op op; | ||
132 | int rc; | ||
133 | }; | ||
134 | |||
135 | /* Function type for magnetic tape commands */ | ||
136 | typedef int (*tape_mtop_fn)(struct tape_device *, int); | ||
137 | |||
138 | /* Size of the array containing the mtops for a discipline */ | ||
139 | #define TAPE_NR_MTOPS (MTMKPART+1) | ||
140 | |||
141 | /* Tape Discipline */ | ||
142 | struct tape_discipline { | ||
143 | struct module *owner; | ||
144 | int (*setup_device)(struct tape_device *); | ||
145 | void (*cleanup_device)(struct tape_device *); | ||
146 | int (*irq)(struct tape_device *, struct tape_request *, struct irb *); | ||
147 | struct tape_request *(*read_block)(struct tape_device *, size_t); | ||
148 | struct tape_request *(*write_block)(struct tape_device *, size_t); | ||
149 | void (*process_eov)(struct tape_device*); | ||
150 | #ifdef CONFIG_S390_TAPE_BLOCK | ||
151 | /* Block device stuff. */ | ||
152 | struct tape_request *(*bread)(struct tape_device *, struct request *); | ||
153 | void (*check_locate)(struct tape_device *, struct tape_request *); | ||
154 | void (*free_bread)(struct tape_request *); | ||
155 | #endif | ||
156 | /* ioctl function for additional ioctls. */ | ||
157 | int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long); | ||
158 | /* Array of tape commands with TAPE_NR_MTOPS entries */ | ||
159 | tape_mtop_fn *mtop_array; | ||
160 | }; | ||
161 | |||
162 | /* | ||
163 | * The discipline irq function either returns an error code (<0) which | ||
164 | * means that the request has failed with an error or one of the following: | ||
165 | */ | ||
166 | #define TAPE_IO_SUCCESS 0 /* request successful */ | ||
167 | #define TAPE_IO_PENDING 1 /* request still running */ | ||
168 | #define TAPE_IO_RETRY 2 /* retry to current request */ | ||
169 | #define TAPE_IO_STOP 3 /* stop the running request */ | ||
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 | |||
177 | #ifdef CONFIG_S390_TAPE_BLOCK | ||
178 | /* Block Frontend Data */ | ||
179 | struct tape_blk_data | ||
180 | { | ||
181 | /* Block device request queue. */ | ||
182 | request_queue_t * request_queue; | ||
183 | spinlock_t request_queue_lock; | ||
184 | |||
185 | /* Task to move entries from block request to CCS request queue. */ | ||
186 | struct work_struct requeue_task; | ||
187 | atomic_t requeue_scheduled; | ||
188 | |||
189 | /* Current position on the tape. */ | ||
190 | long block_position; | ||
191 | int medium_changed; | ||
192 | struct gendisk * disk; | ||
193 | }; | ||
194 | #endif | ||
195 | |||
196 | /* Tape Info */ | ||
197 | struct tape_device { | ||
198 | /* entry in tape_device_list */ | ||
199 | struct list_head node; | ||
200 | |||
201 | int cdev_id; | ||
202 | struct ccw_device * cdev; | ||
203 | struct tape_class_device * nt; | ||
204 | struct tape_class_device * rt; | ||
205 | |||
206 | /* Device discipline information. */ | ||
207 | struct tape_discipline * discipline; | ||
208 | void * discdata; | ||
209 | |||
210 | /* Generic status flags */ | ||
211 | long tape_generic_status; | ||
212 | |||
213 | /* Device state information. */ | ||
214 | wait_queue_head_t state_change_wq; | ||
215 | enum tape_state tape_state; | ||
216 | enum tape_medium_state medium_state; | ||
217 | unsigned char * modeset_byte; | ||
218 | |||
219 | /* Reference count. */ | ||
220 | atomic_t ref_count; | ||
221 | |||
222 | /* Request queue. */ | ||
223 | struct list_head req_queue; | ||
224 | |||
225 | /* Each tape device has (currently) two minor numbers. */ | ||
226 | int first_minor; | ||
227 | |||
228 | /* Number of tapemarks required for correct termination. */ | ||
229 | int required_tapemarks; | ||
230 | |||
231 | /* Block ID of the BOF */ | ||
232 | unsigned int bof; | ||
233 | |||
234 | /* Character device frontend data */ | ||
235 | struct tape_char_data char_data; | ||
236 | #ifdef CONFIG_S390_TAPE_BLOCK | ||
237 | /* Block dev frontend data */ | ||
238 | struct tape_blk_data blk_data; | ||
239 | #endif | ||
240 | }; | ||
241 | |||
242 | /* Externals from tape_core.c */ | ||
243 | extern struct tape_request *tape_alloc_request(int cplength, int datasize); | ||
244 | extern void tape_free_request(struct tape_request *); | ||
245 | extern int tape_do_io(struct tape_device *, struct tape_request *); | ||
246 | extern int tape_do_io_async(struct tape_device *, struct tape_request *); | ||
247 | extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *); | ||
248 | void tape_hotplug_event(struct tape_device *, int major, int action); | ||
249 | |||
250 | static inline int | ||
251 | tape_do_io_free(struct tape_device *device, struct tape_request *request) | ||
252 | { | ||
253 | int rc; | ||
254 | |||
255 | rc = tape_do_io(device, request); | ||
256 | tape_free_request(request); | ||
257 | return rc; | ||
258 | } | ||
259 | |||
260 | extern int tape_oper_handler(int irq, int status); | ||
261 | extern void tape_noper_handler(int irq, int status); | ||
262 | extern int tape_open(struct tape_device *); | ||
263 | extern int tape_release(struct tape_device *); | ||
264 | extern int tape_mtop(struct tape_device *, int, int); | ||
265 | extern void tape_state_set(struct tape_device *, enum tape_state); | ||
266 | |||
267 | extern int tape_generic_online(struct tape_device *, struct tape_discipline *); | ||
268 | extern int tape_generic_offline(struct tape_device *device); | ||
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 | |||
274 | extern struct tape_device *tape_get_device(int devindex); | ||
275 | extern struct tape_device *tape_get_device_reference(struct tape_device *); | ||
276 | extern struct tape_device *tape_put_device(struct tape_device *); | ||
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 | |||
284 | /* Externals from tape_block.c */ | ||
285 | #ifdef CONFIG_S390_TAPE_BLOCK | ||
286 | extern int tapeblock_init (void); | ||
287 | extern void tapeblock_exit(void); | ||
288 | extern int tapeblock_setup_device(struct tape_device *); | ||
289 | extern void tapeblock_cleanup_device(struct tape_device *); | ||
290 | #else | ||
291 | static inline int tapeblock_init (void) {return 0;} | ||
292 | static inline void tapeblock_exit (void) {;} | ||
293 | static inline int tapeblock_setup_device(struct tape_device *t) {return 0;} | ||
294 | static inline void tapeblock_cleanup_device (struct tape_device *t) {;} | ||
295 | #endif | ||
296 | |||
297 | /* tape initialisation functions */ | ||
298 | #ifdef CONFIG_PROC_FS | ||
299 | extern void tape_proc_init (void); | ||
300 | extern void tape_proc_cleanup (void); | ||
301 | #else | ||
302 | static inline void tape_proc_init (void) {;} | ||
303 | static inline void tape_proc_cleanup (void) {;} | ||
304 | #endif | ||
305 | |||
306 | /* a function for dumping device sense info */ | ||
307 | extern void tape_dump_sense(struct tape_device *, struct tape_request *, | ||
308 | struct irb *); | ||
309 | extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *, | ||
310 | struct irb *); | ||
311 | |||
312 | /* functions for handling the status of a device */ | ||
313 | extern void tape_med_state_set(struct tape_device *, enum tape_medium_state); | ||
314 | |||
315 | /* The debug area */ | ||
316 | extern debug_info_t *TAPE_DBF_AREA; | ||
317 | |||
318 | /* functions for building ccws */ | ||
319 | static inline struct ccw1 * | ||
320 | tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda) | ||
321 | { | ||
322 | ccw->cmd_code = cmd_code; | ||
323 | ccw->flags = CCW_FLAG_CC; | ||
324 | ccw->count = memsize; | ||
325 | ccw->cda = (__u32)(addr_t) cda; | ||
326 | return ccw + 1; | ||
327 | } | ||
328 | |||
329 | static inline struct ccw1 * | ||
330 | tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda) | ||
331 | { | ||
332 | ccw->cmd_code = cmd_code; | ||
333 | ccw->flags = 0; | ||
334 | ccw->count = memsize; | ||
335 | ccw->cda = (__u32)(addr_t) cda; | ||
336 | return ccw + 1; | ||
337 | } | ||
338 | |||
339 | static inline struct ccw1 * | ||
340 | tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code) | ||
341 | { | ||
342 | ccw->cmd_code = cmd_code; | ||
343 | ccw->flags = 0; | ||
344 | ccw->count = 0; | ||
345 | ccw->cda = (__u32)(addr_t) &ccw->cmd_code; | ||
346 | return ccw + 1; | ||
347 | } | ||
348 | |||
349 | static inline struct ccw1 * | ||
350 | tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count) | ||
351 | { | ||
352 | while (count-- > 0) { | ||
353 | ccw->cmd_code = cmd_code; | ||
354 | ccw->flags = CCW_FLAG_CC; | ||
355 | ccw->count = 0; | ||
356 | ccw->cda = (__u32)(addr_t) &ccw->cmd_code; | ||
357 | ccw++; | ||
358 | } | ||
359 | return ccw; | ||
360 | } | ||
361 | |||
362 | static inline struct ccw1 * | ||
363 | tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal) | ||
364 | { | ||
365 | ccw->cmd_code = cmd_code; | ||
366 | ccw->flags = CCW_FLAG_CC; | ||
367 | idal_buffer_set_cda(idal, ccw); | ||
368 | return ccw++; | ||
369 | } | ||
370 | |||
371 | static inline struct ccw1 * | ||
372 | tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal) | ||
373 | { | ||
374 | ccw->cmd_code = cmd_code; | ||
375 | ccw->flags = 0; | ||
376 | idal_buffer_set_cda(idal, ccw); | ||
377 | return ccw++; | ||
378 | } | ||
379 | |||
380 | /* Global vars */ | ||
381 | extern const char *tape_state_verbose[]; | ||
382 | extern const char *tape_op_verbose[]; | ||
383 | |||
384 | #endif /* for ifdef tape.h */ | ||