1
2
3
4
5
6
7
8
9
10
11
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/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
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
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
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,
81 TO_BSB,
82 TO_BSF,
83 TO_DSE,
84 TO_FSB,
85 TO_FSF,
86 TO_LBL,
87 TO_NOP,
88 TO_RBA,
89 TO_RBI,
90 TO_RFO,
91 TO_REW,
92 TO_RUN,
93 TO_WRI,
94 TO_WTM,
95 TO_MSEN,
96 TO_LOAD,
97 TO_READ_CONFIG,
98 TO_READ_ATTMSG,
99 TO_DIS,
100 TO_ASSIGN,
101 TO_UNASSIGN,
102 TO_CRYPT_ON,
103 TO_CRYPT_OFF,
104 TO_KEKL_SET,
105 TO_KEKL_QUERY,
106 TO_RDC,
107 TO_SIZE,
108};
109
110
111struct tape_device;
112
113
114enum tape_request_status {
115 TAPE_REQUEST_INIT,
116 TAPE_REQUEST_QUEUED,
117 TAPE_REQUEST_IN_IO,
118 TAPE_REQUEST_DONE,
119 TAPE_REQUEST_CANCEL,
120 TAPE_REQUEST_LONG_BUSY,
121};
122
123
124struct tape_request {
125 struct list_head list;
126 struct tape_device *device;
127 struct ccw1 *cpaddr;
128 void *cpdata;
129 enum tape_request_status status;
130 int options;
131 int retries;
132 int rescnt;
133
134
135 void (*callback)(struct tape_request *, void *);
136 void *callback_data;
137
138 enum tape_op op;
139 int rc;
140};
141
142
143typedef int (*tape_mtop_fn)(struct tape_device *, int);
144
145
146#define TAPE_NR_MTOPS (MTMKPART+1)
147
148
149struct tape_discipline {
150 struct module *owner;
151 int (*setup_device)(struct tape_device *);
152 void (*cleanup_device)(struct tape_device *);
153 int (*irq)(struct tape_device *, struct tape_request *, struct irb *);
154 struct tape_request *(*read_block)(struct tape_device *, size_t);
155 struct tape_request *(*write_block)(struct tape_device *, size_t);
156 void (*process_eov)(struct tape_device*);
157#ifdef CONFIG_S390_TAPE_BLOCK
158
159 struct tape_request *(*bread)(struct tape_device *, struct request *);
160 void (*check_locate)(struct tape_device *, struct tape_request *);
161 void (*free_bread)(struct tape_request *);
162#endif
163
164 int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
165
166 tape_mtop_fn *mtop_array;
167};
168
169
170
171
172
173#define TAPE_IO_SUCCESS 0
174#define TAPE_IO_PENDING 1
175#define TAPE_IO_RETRY 2
176#define TAPE_IO_STOP 3
177#define TAPE_IO_LONG_BUSY 4
178
179
180struct tape_char_data {
181 struct idal_buffer *idal_buf;
182 int block_size;
183};
184
185#ifdef CONFIG_S390_TAPE_BLOCK
186
187struct tape_blk_data
188{
189 struct tape_device * device;
190
191 struct request_queue * request_queue;
192 spinlock_t request_queue_lock;
193
194
195 struct work_struct requeue_task;
196 atomic_t requeue_scheduled;
197
198
199 long block_position;
200 int medium_changed;
201 struct gendisk * disk;
202};
203#endif
204
205
206struct tape_device {
207
208 struct list_head node;
209
210 int cdev_id;
211 struct ccw_device * cdev;
212 struct tape_class_device * nt;
213 struct tape_class_device * rt;
214
215
216 struct tape_discipline * discipline;
217 void * discdata;
218
219
220 long tape_generic_status;
221
222
223 wait_queue_head_t state_change_wq;
224 enum tape_state tape_state;
225 enum tape_medium_state medium_state;
226 unsigned char * modeset_byte;
227
228
229 atomic_t ref_count;
230
231
232 struct list_head req_queue;
233
234
235 wait_queue_head_t wait_queue;
236
237
238 int first_minor;
239
240
241 int required_tapemarks;
242
243
244 unsigned int bof;
245
246
247 struct tape_char_data char_data;
248#ifdef CONFIG_S390_TAPE_BLOCK
249
250 struct tape_blk_data blk_data;
251#endif
252
253
254 struct delayed_work tape_dnr;
255
256
257 struct timer_list lb_timeout;
258
259};
260
261
262extern struct tape_request *tape_alloc_request(int cplength, int datasize);
263extern void tape_free_request(struct tape_request *);
264extern int tape_do_io(struct tape_device *, struct tape_request *);
265extern int tape_do_io_async(struct tape_device *, struct tape_request *);
266extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
267extern int tape_cancel_io(struct tape_device *, struct tape_request *);
268void tape_hotplug_event(struct tape_device *, int major, int action);
269
270static inline int
271tape_do_io_free(struct tape_device *device, struct tape_request *request)
272{
273 int rc;
274
275 rc = tape_do_io(device, request);
276 tape_free_request(request);
277 return rc;
278}
279
280extern int tape_oper_handler(int irq, int status);
281extern void tape_noper_handler(int irq, int status);
282extern int tape_open(struct tape_device *);
283extern int tape_release(struct tape_device *);
284extern int tape_mtop(struct tape_device *, int, int);
285extern void tape_state_set(struct tape_device *, enum tape_state);
286
287extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
288extern int tape_generic_offline(struct ccw_device *);
289
290
291extern int tape_generic_probe(struct ccw_device *);
292extern void tape_generic_remove(struct ccw_device *);
293
294extern struct tape_device *tape_get_device(int devindex);
295extern struct tape_device *tape_get_device_reference(struct tape_device *);
296extern struct tape_device *tape_put_device(struct tape_device *);
297
298
299extern int tapechar_init(void);
300extern void tapechar_exit(void);
301extern int tapechar_setup_device(struct tape_device *);
302extern void tapechar_cleanup_device(struct tape_device *);
303
304
305#ifdef CONFIG_S390_TAPE_BLOCK
306extern int tapeblock_init (void);
307extern void tapeblock_exit(void);
308extern int tapeblock_setup_device(struct tape_device *);
309extern void tapeblock_cleanup_device(struct tape_device *);
310#else
311static inline int tapeblock_init (void) {return 0;}
312static inline void tapeblock_exit (void) {;}
313static inline int tapeblock_setup_device(struct tape_device *t) {return 0;}
314static inline void tapeblock_cleanup_device (struct tape_device *t) {;}
315#endif
316
317
318#ifdef CONFIG_PROC_FS
319extern void tape_proc_init (void);
320extern void tape_proc_cleanup (void);
321#else
322static inline void tape_proc_init (void) {;}
323static inline void tape_proc_cleanup (void) {;}
324#endif
325
326
327extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
328 struct irb *);
329
330
331extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
332
333
334extern debug_info_t *TAPE_DBF_AREA;
335
336
337static inline struct ccw1 *
338tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
339{
340 ccw->cmd_code = cmd_code;
341 ccw->flags = CCW_FLAG_CC;
342 ccw->count = memsize;
343 ccw->cda = (__u32)(addr_t) cda;
344 return ccw + 1;
345}
346
347static inline struct ccw1 *
348tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
349{
350 ccw->cmd_code = cmd_code;
351 ccw->flags = 0;
352 ccw->count = memsize;
353 ccw->cda = (__u32)(addr_t) cda;
354 return ccw + 1;
355}
356
357static inline struct ccw1 *
358tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
359{
360 ccw->cmd_code = cmd_code;
361 ccw->flags = 0;
362 ccw->count = 0;
363 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
364 return ccw + 1;
365}
366
367static inline struct ccw1 *
368tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
369{
370 while (count-- > 0) {
371 ccw->cmd_code = cmd_code;
372 ccw->flags = CCW_FLAG_CC;
373 ccw->count = 0;
374 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
375 ccw++;
376 }
377 return ccw;
378}
379
380static inline struct ccw1 *
381tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
382{
383 ccw->cmd_code = cmd_code;
384 ccw->flags = CCW_FLAG_CC;
385 idal_buffer_set_cda(idal, ccw);
386 return ccw++;
387}
388
389static inline struct ccw1 *
390tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
391{
392 ccw->cmd_code = cmd_code;
393 ccw->flags = 0;
394 idal_buffer_set_cda(idal, ccw);
395 return ccw++;
396}
397
398
399extern const char *tape_state_verbose[];
400extern const char *tape_op_verbose[];
401
402#endif
403