blob: bb4ff537729deb53fbcb629b7e47278643fd406a [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
Michael Holzheucced1dd2007-02-05 21:18:26 +01006 * Copyright IBM Corp. 2001,2006
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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#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
26struct 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, ...) \
34do { \
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...) \
45do { \
46 debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
47} while (0)
48
49#define DBF_EXCEPTION(d_level, d_str...) \
50do { \
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
63enum tape_medium_state {
64 MS_UNKNOWN,
65 MS_LOADED,
66 MS_UNLOADED,
67 MS_SIZE
68};
69
70enum 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
79enum 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 */
Michael Holzheucced1dd2007-02-05 21:18:26 +0100102 TO_CRYPT_ON, /* Enable encrpytion */
103 TO_CRYPT_OFF, /* Disable encrpytion */
104 TO_KEKL_SET, /* Set KEK label */
105 TO_KEKL_QUERY, /* Query KEK label */
106 TO_SIZE, /* #entries in tape_op_t */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107};
108
109/* Forward declaration */
110struct tape_device;
111
112/* tape_request->status can be: */
113enum tape_request_status {
114 TAPE_REQUEST_INIT, /* request is ready to be processed */
115 TAPE_REQUEST_QUEUED, /* request is queued to be processed */
116 TAPE_REQUEST_IN_IO, /* request is currently in IO */
117 TAPE_REQUEST_DONE, /* request is completed. */
Stefan Bader41117962005-07-27 11:45:04 -0700118 TAPE_REQUEST_CANCEL, /* request should be canceled. */
Michael Holzheucced1dd2007-02-05 21:18:26 +0100119 TAPE_REQUEST_LONG_BUSY, /* request has to be restarted after long busy */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120};
121
122/* Tape CCW request */
123struct tape_request {
124 struct list_head list; /* list head for request queueing. */
125 struct tape_device *device; /* tape device of this request */
126 struct ccw1 *cpaddr; /* address of the channel program. */
127 void *cpdata; /* pointer to ccw data. */
128 enum tape_request_status status;/* status of this request */
129 int options; /* options for execution. */
130 int retries; /* retry counter for error recovery. */
131 int rescnt; /* residual count from devstat. */
132
133 /* Callback for delivering final status. */
134 void (*callback)(struct tape_request *, void *);
135 void *callback_data;
136
137 enum tape_op op;
138 int rc;
139};
140
141/* Function type for magnetic tape commands */
142typedef int (*tape_mtop_fn)(struct tape_device *, int);
143
144/* Size of the array containing the mtops for a discipline */
145#define TAPE_NR_MTOPS (MTMKPART+1)
146
147/* Tape Discipline */
148struct tape_discipline {
149 struct module *owner;
150 int (*setup_device)(struct tape_device *);
151 void (*cleanup_device)(struct tape_device *);
152 int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
153 struct tape_request *(*read_block)(struct tape_device *, size_t);
154 struct tape_request *(*write_block)(struct tape_device *, size_t);
155 void (*process_eov)(struct tape_device*);
156#ifdef CONFIG_S390_TAPE_BLOCK
157 /* Block device stuff. */
158 struct tape_request *(*bread)(struct tape_device *, struct request *);
159 void (*check_locate)(struct tape_device *, struct tape_request *);
160 void (*free_bread)(struct tape_request *);
161#endif
162 /* ioctl function for additional ioctls. */
163 int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
164 /* Array of tape commands with TAPE_NR_MTOPS entries */
165 tape_mtop_fn *mtop_array;
166};
167
168/*
169 * The discipline irq function either returns an error code (<0) which
170 * means that the request has failed with an error or one of the following:
171 */
Michael Holzheucced1dd2007-02-05 21:18:26 +0100172#define TAPE_IO_SUCCESS 0 /* request successful */
173#define TAPE_IO_PENDING 1 /* request still running */
174#define TAPE_IO_RETRY 2 /* retry to current request */
175#define TAPE_IO_STOP 3 /* stop the running request */
176#define TAPE_IO_LONG_BUSY 4 /* delay the running request */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178/* Char Frontend Data */
179struct tape_char_data {
180 struct idal_buffer *idal_buf; /* idal buffer for user char data */
181 int block_size; /* of size block_size. */
182};
183
184#ifdef CONFIG_S390_TAPE_BLOCK
185/* Block Frontend Data */
186struct tape_blk_data
187{
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100188 struct tape_device * device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 /* Block device request queue. */
190 request_queue_t * request_queue;
191 spinlock_t request_queue_lock;
192
193 /* Task to move entries from block request to CCS request queue. */
194 struct work_struct requeue_task;
195 atomic_t requeue_scheduled;
196
197 /* Current position on the tape. */
198 long block_position;
199 int medium_changed;
200 struct gendisk * disk;
201};
202#endif
203
204/* Tape Info */
205struct tape_device {
206 /* entry in tape_device_list */
207 struct list_head node;
208
209 int cdev_id;
210 struct ccw_device * cdev;
211 struct tape_class_device * nt;
212 struct tape_class_device * rt;
213
214 /* Device discipline information. */
215 struct tape_discipline * discipline;
216 void * discdata;
217
218 /* Generic status flags */
219 long tape_generic_status;
220
221 /* Device state information. */
222 wait_queue_head_t state_change_wq;
223 enum tape_state tape_state;
224 enum tape_medium_state medium_state;
225 unsigned char * modeset_byte;
226
227 /* Reference count. */
228 atomic_t ref_count;
229
230 /* Request queue. */
231 struct list_head req_queue;
232
233 /* Each tape device has (currently) two minor numbers. */
234 int first_minor;
235
236 /* Number of tapemarks required for correct termination. */
237 int required_tapemarks;
238
239 /* Block ID of the BOF */
240 unsigned int bof;
241
242 /* Character device frontend data */
243 struct tape_char_data char_data;
244#ifdef CONFIG_S390_TAPE_BLOCK
245 /* Block dev frontend data */
246 struct tape_blk_data blk_data;
247#endif
Stefan Bader41117962005-07-27 11:45:04 -0700248
249 /* Function to start or stop the next request later. */
Martin Schwidefskyc1637532006-12-08 15:53:57 +0100250 struct delayed_work tape_dnr;
Michael Holzheucced1dd2007-02-05 21:18:26 +0100251
252 /* Timer for long busy */
253 struct timer_list lb_timeout;
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255};
256
257/* Externals from tape_core.c */
258extern struct tape_request *tape_alloc_request(int cplength, int datasize);
259extern void tape_free_request(struct tape_request *);
260extern int tape_do_io(struct tape_device *, struct tape_request *);
261extern int tape_do_io_async(struct tape_device *, struct tape_request *);
262extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
Michael Holzheu5f384332006-03-24 03:15:28 -0800263extern int tape_cancel_io(struct tape_device *, struct tape_request *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264void tape_hotplug_event(struct tape_device *, int major, int action);
265
266static inline int
267tape_do_io_free(struct tape_device *device, struct tape_request *request)
268{
269 int rc;
270
271 rc = tape_do_io(device, request);
272 tape_free_request(request);
273 return rc;
274}
275
276extern int tape_oper_handler(int irq, int status);
277extern void tape_noper_handler(int irq, int status);
278extern int tape_open(struct tape_device *);
279extern int tape_release(struct tape_device *);
280extern int tape_mtop(struct tape_device *, int, int);
281extern void tape_state_set(struct tape_device *, enum tape_state);
282
283extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
284extern int tape_generic_offline(struct tape_device *device);
285
286/* Externals from tape_devmap.c */
287extern int tape_generic_probe(struct ccw_device *);
288extern void tape_generic_remove(struct ccw_device *);
289
290extern struct tape_device *tape_get_device(int devindex);
291extern struct tape_device *tape_get_device_reference(struct tape_device *);
292extern struct tape_device *tape_put_device(struct tape_device *);
293
294/* Externals from tape_char.c */
295extern int tapechar_init(void);
296extern void tapechar_exit(void);
297extern int tapechar_setup_device(struct tape_device *);
298extern void tapechar_cleanup_device(struct tape_device *);
299
300/* Externals from tape_block.c */
301#ifdef CONFIG_S390_TAPE_BLOCK
302extern int tapeblock_init (void);
303extern void tapeblock_exit(void);
304extern int tapeblock_setup_device(struct tape_device *);
305extern void tapeblock_cleanup_device(struct tape_device *);
306#else
307static inline int tapeblock_init (void) {return 0;}
308static inline void tapeblock_exit (void) {;}
309static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
310static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
311#endif
312
313/* tape initialisation functions */
314#ifdef CONFIG_PROC_FS
315extern void tape_proc_init (void);
316extern void tape_proc_cleanup (void);
317#else
318static inline void tape_proc_init (void) {;}
319static inline void tape_proc_cleanup (void) {;}
320#endif
321
322/* a function for dumping device sense info */
323extern void tape_dump_sense(struct tape_device *, struct tape_request *,
324 struct irb *);
325extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
326 struct irb *);
327
328/* functions for handling the status of a device */
329extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
330
331/* The debug area */
332extern debug_info_t *TAPE_DBF_AREA;
333
334/* functions for building ccws */
335static inline struct ccw1 *
336tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
337{
338 ccw->cmd_code = cmd_code;
339 ccw->flags = CCW_FLAG_CC;
340 ccw->count = memsize;
341 ccw->cda = (__u32)(addr_t) cda;
342 return ccw + 1;
343}
344
345static inline struct ccw1 *
346tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
347{
348 ccw->cmd_code = cmd_code;
349 ccw->flags = 0;
350 ccw->count = memsize;
351 ccw->cda = (__u32)(addr_t) cda;
352 return ccw + 1;
353}
354
355static inline struct ccw1 *
356tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
357{
358 ccw->cmd_code = cmd_code;
359 ccw->flags = 0;
360 ccw->count = 0;
361 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
362 return ccw + 1;
363}
364
365static inline struct ccw1 *
366tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
367{
368 while (count-- > 0) {
369 ccw->cmd_code = cmd_code;
370 ccw->flags = CCW_FLAG_CC;
371 ccw->count = 0;
372 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
373 ccw++;
374 }
375 return ccw;
376}
377
378static inline struct ccw1 *
379tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
380{
381 ccw->cmd_code = cmd_code;
382 ccw->flags = CCW_FLAG_CC;
383 idal_buffer_set_cda(idal, ccw);
384 return ccw++;
385}
386
387static inline struct ccw1 *
388tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
389{
390 ccw->cmd_code = cmd_code;
391 ccw->flags = 0;
392 idal_buffer_set_cda(idal, ccw);
393 return ccw++;
394}
395
396/* Global vars */
397extern const char *tape_state_verbose[];
398extern const char *tape_op_verbose[];
399
400#endif /* for ifdef tape.h */