blob: 01d865d937917f5e83c5be620921ea0d9569641b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/s390/char/tape.h
3 * tape device driver for 3480/3490E/3590 tapes.
4 *
5 * S390 and zSeries version
Stefan Bader41117962005-07-27 11:45:04 -07006 * Copyright (C) 2001,2005 IBM Deutschland Entwicklung GmbH, IBM Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Author(s): Carsten Otte <cotte@de.ibm.com>
8 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
9 * Martin Schwidefsky <schwidefsky@de.ibm.com>
Stefan Bader41117962005-07-27 11:45:04 -070010 * Stefan Bader <shbader@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
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/config.h>
20#include <linux/blkdev.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/mtio.h>
24#include <linux/interrupt.h>
25#include <linux/workqueue.h>
26
27struct gendisk;
28
29/*
30 * Define DBF_LIKE_HELL for lots of messages in the debug feature.
31 */
32#define DBF_LIKE_HELL
33#ifdef DBF_LIKE_HELL
34#define DBF_LH(level, str, ...) \
35do { \
36 debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
37} while (0)
38#else
39#define DBF_LH(level, str, ...) do {} while(0)
40#endif
41
42/*
43 * macros s390 debug feature (dbf)
44 */
45#define DBF_EVENT(d_level, d_str...) \
46do { \
47 debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
48} while (0)
49
50#define DBF_EXCEPTION(d_level, d_str...) \
51do { \
52 debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
53} while (0)
54
55#define TAPE_VERSION_MAJOR 2
56#define TAPE_VERSION_MINOR 0
57#define TAPE_MAGIC "tape"
58
59#define TAPE_MINORS_PER_DEV 2 /* two minors per device */
60#define TAPEBLOCK_HSEC_SIZE 2048
61#define TAPEBLOCK_HSEC_S2B 2
62#define TAPEBLOCK_RETRIES 5
63
64enum tape_medium_state {
65 MS_UNKNOWN,
66 MS_LOADED,
67 MS_UNLOADED,
68 MS_SIZE
69};
70
71enum tape_state {
72 TS_UNUSED=0,
73 TS_IN_USE,
74 TS_BLKUSE,
75 TS_INIT,
76 TS_NOT_OPER,
77 TS_SIZE
78};
79
80enum tape_op {
81 TO_BLOCK, /* Block read */
82 TO_BSB, /* Backward space block */
83 TO_BSF, /* Backward space filemark */
84 TO_DSE, /* Data security erase */
85 TO_FSB, /* Forward space block */
86 TO_FSF, /* Forward space filemark */
87 TO_LBL, /* Locate block label */
88 TO_NOP, /* No operation */
89 TO_RBA, /* Read backward */
90 TO_RBI, /* Read block information */
91 TO_RFO, /* Read forward */
92 TO_REW, /* Rewind tape */
93 TO_RUN, /* Rewind and unload tape */
94 TO_WRI, /* Write block */
95 TO_WTM, /* Write tape mark */
96 TO_MSEN, /* Medium sense */
97 TO_LOAD, /* Load tape */
98 TO_READ_CONFIG, /* Read configuration data */
99 TO_READ_ATTMSG, /* Read attention message */
100 TO_DIS, /* Tape display */
101 TO_ASSIGN, /* Assign tape to channel path */
102 TO_UNASSIGN, /* Unassign tape from channel path */
103 TO_SIZE /* #entries in tape_op_t */
104};
105
106/* Forward declaration */
107struct tape_device;
108
109/* tape_request->status can be: */
110enum tape_request_status {
111 TAPE_REQUEST_INIT, /* request is ready to be processed */
112 TAPE_REQUEST_QUEUED, /* request is queued to be processed */
113 TAPE_REQUEST_IN_IO, /* request is currently in IO */
114 TAPE_REQUEST_DONE, /* request is completed. */
Stefan Bader41117962005-07-27 11:45:04 -0700115 TAPE_REQUEST_CANCEL, /* request should be canceled. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116};
117
118/* Tape CCW request */
119struct 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
129 /* Callback for delivering final status. */
130 void (*callback)(struct tape_request *, void *);
131 void *callback_data;
132
133 enum tape_op op;
134 int rc;
135};
136
137/* Function type for magnetic tape commands */
138typedef int (*tape_mtop_fn)(struct tape_device *, int);
139
140/* Size of the array containing the mtops for a discipline */
141#define TAPE_NR_MTOPS (MTMKPART+1)
142
143/* Tape Discipline */
144struct tape_discipline {
145 struct module *owner;
146 int (*setup_device)(struct tape_device *);
147 void (*cleanup_device)(struct tape_device *);
148 int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
149 struct tape_request *(*read_block)(struct tape_device *, size_t);
150 struct tape_request *(*write_block)(struct tape_device *, size_t);
151 void (*process_eov)(struct tape_device*);
152#ifdef CONFIG_S390_TAPE_BLOCK
153 /* Block device stuff. */
154 struct tape_request *(*bread)(struct tape_device *, struct request *);
155 void (*check_locate)(struct tape_device *, struct tape_request *);
156 void (*free_bread)(struct tape_request *);
157#endif
158 /* ioctl function for additional ioctls. */
159 int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
160 /* Array of tape commands with TAPE_NR_MTOPS entries */
161 tape_mtop_fn *mtop_array;
162};
163
164/*
165 * The discipline irq function either returns an error code (<0) which
166 * means that the request has failed with an error or one of the following:
167 */
168#define TAPE_IO_SUCCESS 0 /* request successful */
169#define TAPE_IO_PENDING 1 /* request still running */
170#define TAPE_IO_RETRY 2 /* retry to current request */
171#define TAPE_IO_STOP 3 /* stop the running request */
172
173/* Char Frontend Data */
174struct tape_char_data {
175 struct idal_buffer *idal_buf; /* idal buffer for user char data */
176 int block_size; /* of size block_size. */
177};
178
179#ifdef CONFIG_S390_TAPE_BLOCK
180/* Block Frontend Data */
181struct tape_blk_data
182{
183 /* Block device request queue. */
184 request_queue_t * request_queue;
185 spinlock_t request_queue_lock;
186
187 /* Task to move entries from block request to CCS request queue. */
188 struct work_struct requeue_task;
189 atomic_t requeue_scheduled;
190
191 /* Current position on the tape. */
192 long block_position;
193 int medium_changed;
194 struct gendisk * disk;
195};
196#endif
197
198/* Tape Info */
199struct tape_device {
200 /* entry in tape_device_list */
201 struct list_head node;
202
203 int cdev_id;
204 struct ccw_device * cdev;
205 struct tape_class_device * nt;
206 struct tape_class_device * rt;
207
208 /* Device discipline information. */
209 struct tape_discipline * discipline;
210 void * discdata;
211
212 /* Generic status flags */
213 long tape_generic_status;
214
215 /* Device state information. */
216 wait_queue_head_t state_change_wq;
217 enum tape_state tape_state;
218 enum tape_medium_state medium_state;
219 unsigned char * modeset_byte;
220
221 /* Reference count. */
222 atomic_t ref_count;
223
224 /* Request queue. */
225 struct list_head req_queue;
226
227 /* Each tape device has (currently) two minor numbers. */
228 int first_minor;
229
230 /* Number of tapemarks required for correct termination. */
231 int required_tapemarks;
232
233 /* Block ID of the BOF */
234 unsigned int bof;
235
236 /* Character device frontend data */
237 struct tape_char_data char_data;
238#ifdef CONFIG_S390_TAPE_BLOCK
239 /* Block dev frontend data */
240 struct tape_blk_data blk_data;
241#endif
Stefan Bader41117962005-07-27 11:45:04 -0700242
243 /* Function to start or stop the next request later. */
244 struct work_struct tape_dnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245};
246
247/* Externals from tape_core.c */
248extern struct tape_request *tape_alloc_request(int cplength, int datasize);
249extern void tape_free_request(struct tape_request *);
250extern int tape_do_io(struct tape_device *, struct tape_request *);
251extern int tape_do_io_async(struct tape_device *, struct tape_request *);
252extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
253void tape_hotplug_event(struct tape_device *, int major, int action);
254
255static inline int
256tape_do_io_free(struct tape_device *device, struct tape_request *request)
257{
258 int rc;
259
260 rc = tape_do_io(device, request);
261 tape_free_request(request);
262 return rc;
263}
264
265extern int tape_oper_handler(int irq, int status);
266extern void tape_noper_handler(int irq, int status);
267extern int tape_open(struct tape_device *);
268extern int tape_release(struct tape_device *);
269extern int tape_mtop(struct tape_device *, int, int);
270extern void tape_state_set(struct tape_device *, enum tape_state);
271
272extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
273extern int tape_generic_offline(struct tape_device *device);
274
275/* Externals from tape_devmap.c */
276extern int tape_generic_probe(struct ccw_device *);
277extern void tape_generic_remove(struct ccw_device *);
278
279extern struct tape_device *tape_get_device(int devindex);
280extern struct tape_device *tape_get_device_reference(struct tape_device *);
281extern struct tape_device *tape_put_device(struct tape_device *);
282
283/* Externals from tape_char.c */
284extern int tapechar_init(void);
285extern void tapechar_exit(void);
286extern int tapechar_setup_device(struct tape_device *);
287extern void tapechar_cleanup_device(struct tape_device *);
288
289/* Externals from tape_block.c */
290#ifdef CONFIG_S390_TAPE_BLOCK
291extern int tapeblock_init (void);
292extern void tapeblock_exit(void);
293extern int tapeblock_setup_device(struct tape_device *);
294extern void tapeblock_cleanup_device(struct tape_device *);
295#else
296static inline int tapeblock_init (void) {return 0;}
297static inline void tapeblock_exit (void) {;}
298static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
299static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
300#endif
301
302/* tape initialisation functions */
303#ifdef CONFIG_PROC_FS
304extern void tape_proc_init (void);
305extern void tape_proc_cleanup (void);
306#else
307static inline void tape_proc_init (void) {;}
308static inline void tape_proc_cleanup (void) {;}
309#endif
310
311/* a function for dumping device sense info */
312extern void tape_dump_sense(struct tape_device *, struct tape_request *,
313 struct irb *);
314extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
315 struct irb *);
316
317/* functions for handling the status of a device */
318extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
319
320/* The debug area */
321extern debug_info_t *TAPE_DBF_AREA;
322
323/* functions for building ccws */
324static inline struct ccw1 *
325tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
326{
327 ccw->cmd_code = cmd_code;
328 ccw->flags = CCW_FLAG_CC;
329 ccw->count = memsize;
330 ccw->cda = (__u32)(addr_t) cda;
331 return ccw + 1;
332}
333
334static inline struct ccw1 *
335tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
336{
337 ccw->cmd_code = cmd_code;
338 ccw->flags = 0;
339 ccw->count = memsize;
340 ccw->cda = (__u32)(addr_t) cda;
341 return ccw + 1;
342}
343
344static inline struct ccw1 *
345tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
346{
347 ccw->cmd_code = cmd_code;
348 ccw->flags = 0;
349 ccw->count = 0;
350 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
351 return ccw + 1;
352}
353
354static inline struct ccw1 *
355tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
356{
357 while (count-- > 0) {
358 ccw->cmd_code = cmd_code;
359 ccw->flags = CCW_FLAG_CC;
360 ccw->count = 0;
361 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
362 ccw++;
363 }
364 return ccw;
365}
366
367static inline struct ccw1 *
368tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
369{
370 ccw->cmd_code = cmd_code;
371 ccw->flags = CCW_FLAG_CC;
372 idal_buffer_set_cda(idal, ccw);
373 return ccw++;
374}
375
376static inline struct ccw1 *
377tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
378{
379 ccw->cmd_code = cmd_code;
380 ccw->flags = 0;
381 idal_buffer_set_cda(idal, ccw);
382 return ccw++;
383}
384
385/* Global vars */
386extern const char *tape_state_verbose[];
387extern const char *tape_op_verbose[];
388
389#endif /* for ifdef tape.h */