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/kernel.h>
20#include <linux/module.h>
21#include <linux/mtio.h>
22#include <linux/interrupt.h>
23#include <linux/workqueue.h>
24
25struct gendisk;
26
27
28
29
30#define DBF_LIKE_HELL
31#ifdef DBF_LIKE_HELL
32#define DBF_LH(level, str, ...) \
33do { \
34 debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
35} while (0)
36#else
37#define DBF_LH(level, str, ...) do {} while(0)
38#endif
39
40
41
42
43#define DBF_EVENT(d_level, d_str...) \
44do { \
45 debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
46} while (0)
47
48#define DBF_EXCEPTION(d_level, d_str...) \
49do { \
50 debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
51} while (0)
52
53#define TAPE_VERSION_MAJOR 2
54#define TAPE_VERSION_MINOR 0
55#define TAPE_MAGIC "tape"
56
57#define TAPE_MINORS_PER_DEV 2
58#define TAPEBLOCK_HSEC_SIZE 2048
59#define TAPEBLOCK_HSEC_S2B 2
60#define TAPEBLOCK_RETRIES 5
61
62enum tape_medium_state {
63 MS_UNKNOWN,
64 MS_LOADED,
65 MS_UNLOADED,
66 MS_SIZE
67};
68
69enum tape_state {
70 TS_UNUSED=0,
71 TS_IN_USE,
72 TS_BLKUSE,
73 TS_INIT,
74 TS_NOT_OPER,
75 TS_SIZE
76};
77
78enum tape_op {
79 TO_BLOCK,
80 TO_BSB,
81 TO_BSF,
82 TO_DSE,
83 TO_FSB,
84 TO_FSF,
85 TO_LBL,
86 TO_NOP,
87 TO_RBA,
88 TO_RBI,
89 TO_RFO,
90 TO_REW,
91 TO_RUN,
92 TO_WRI,
93 TO_WTM,
94 TO_MSEN,
95 TO_LOAD,
96 TO_READ_CONFIG,
97 TO_READ_ATTMSG,
98 TO_DIS,
99 TO_ASSIGN,
100 TO_UNASSIGN,
101 TO_CRYPT_ON,
102 TO_CRYPT_OFF,
103 TO_KEKL_SET,
104 TO_KEKL_QUERY,
105 TO_RDC,
106 TO_SIZE,
107};
108
109
110struct tape_device;
111
112
113enum tape_request_status {
114 TAPE_REQUEST_INIT,
115 TAPE_REQUEST_QUEUED,
116 TAPE_REQUEST_IN_IO,
117 TAPE_REQUEST_DONE,
118 TAPE_REQUEST_CANCEL,
119 TAPE_REQUEST_LONG_BUSY,
120};
121
122
123struct tape_request {
124 struct list_head list;
125 struct tape_device *device;
126 struct ccw1 *cpaddr;
127 void *cpdata;
128 enum tape_request_status status;
129 int options;
130 int retries;
131 int rescnt;
132
133
134 void (*callback)(struct tape_request *, void *);
135 void *callback_data;
136
137 enum tape_op op;
138 int rc;
139};
140
141
142typedef int (*tape_mtop_fn)(struct tape_device *, int);
143
144
145#define TAPE_NR_MTOPS (MTMKPART+1)
146
147
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
157 int (*ioctl_fn)(struct tape_device *, unsigned int, unsigned long);
158
159 tape_mtop_fn *mtop_array;
160};
161
162
163
164
165
166#define TAPE_IO_SUCCESS 0
167#define TAPE_IO_PENDING 1
168#define TAPE_IO_RETRY 2
169#define TAPE_IO_STOP 3
170#define TAPE_IO_LONG_BUSY 4
171
172
173struct tape_char_data {
174 struct idal_buffer *idal_buf;
175 int block_size;
176};
177
178
179struct tape_device {
180
181 struct list_head node;
182
183 int cdev_id;
184 struct ccw_device * cdev;
185 struct tape_class_device * nt;
186 struct tape_class_device * rt;
187
188
189 struct mutex mutex;
190
191
192 struct tape_discipline * discipline;
193 void * discdata;
194
195
196 long tape_generic_status;
197
198
199 wait_queue_head_t state_change_wq;
200 enum tape_state tape_state;
201 enum tape_medium_state medium_state;
202 unsigned char * modeset_byte;
203
204
205 atomic_t ref_count;
206
207
208 struct list_head req_queue;
209
210
211 wait_queue_head_t wait_queue;
212
213
214 int first_minor;
215
216
217 int required_tapemarks;
218
219
220 unsigned int bof;
221
222
223 struct tape_char_data char_data;
224
225
226 struct delayed_work tape_dnr;
227
228
229 struct timer_list lb_timeout;
230
231};
232
233
234extern struct tape_request *tape_alloc_request(int cplength, int datasize);
235extern void tape_free_request(struct tape_request *);
236extern int tape_do_io(struct tape_device *, struct tape_request *);
237extern int tape_do_io_async(struct tape_device *, struct tape_request *);
238extern int tape_do_io_interruptible(struct tape_device *, struct tape_request *);
239extern int tape_cancel_io(struct tape_device *, struct tape_request *);
240void tape_hotplug_event(struct tape_device *, int major, int action);
241
242static inline int
243tape_do_io_free(struct tape_device *device, struct tape_request *request)
244{
245 int rc;
246
247 rc = tape_do_io(device, request);
248 tape_free_request(request);
249 return rc;
250}
251
252static inline void
253tape_do_io_async_free(struct tape_device *device, struct tape_request *request)
254{
255 request->callback = (void *) tape_free_request;
256 request->callback_data = NULL;
257 tape_do_io_async(device, request);
258}
259
260extern int tape_oper_handler(int irq, int status);
261extern void tape_noper_handler(int irq, int status);
262extern int tape_open(struct tape_device *);
263extern int tape_release(struct tape_device *);
264extern int tape_mtop(struct tape_device *, int, int);
265extern void tape_state_set(struct tape_device *, enum tape_state);
266
267extern int tape_generic_online(struct tape_device *, struct tape_discipline *);
268extern int tape_generic_offline(struct ccw_device *);
269extern int tape_generic_pm_suspend(struct ccw_device *);
270
271
272extern int tape_generic_probe(struct ccw_device *);
273extern void tape_generic_remove(struct ccw_device *);
274
275extern struct tape_device *tape_find_device(int devindex);
276extern struct tape_device *tape_get_device(struct tape_device *);
277extern void tape_put_device(struct tape_device *);
278
279
280extern int tapechar_init(void);
281extern void tapechar_exit(void);
282extern int tapechar_setup_device(struct tape_device *);
283extern void tapechar_cleanup_device(struct tape_device *);
284
285
286#ifdef CONFIG_PROC_FS
287extern void tape_proc_init (void);
288extern void tape_proc_cleanup (void);
289#else
290static inline void tape_proc_init (void) {;}
291static inline void tape_proc_cleanup (void) {;}
292#endif
293
294
295extern void tape_dump_sense_dbf(struct tape_device *, struct tape_request *,
296 struct irb *);
297
298
299extern void tape_med_state_set(struct tape_device *, enum tape_medium_state);
300
301
302extern debug_info_t *TAPE_DBF_AREA;
303
304
305static inline struct ccw1 *
306tape_ccw_cc(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
307{
308 ccw->cmd_code = cmd_code;
309 ccw->flags = CCW_FLAG_CC;
310 ccw->count = memsize;
311 ccw->cda = (__u32)(addr_t) cda;
312 return ccw + 1;
313}
314
315static inline struct ccw1 *
316tape_ccw_end(struct ccw1 *ccw, __u8 cmd_code, __u16 memsize, void *cda)
317{
318 ccw->cmd_code = cmd_code;
319 ccw->flags = 0;
320 ccw->count = memsize;
321 ccw->cda = (__u32)(addr_t) cda;
322 return ccw + 1;
323}
324
325static inline struct ccw1 *
326tape_ccw_cmd(struct ccw1 *ccw, __u8 cmd_code)
327{
328 ccw->cmd_code = cmd_code;
329 ccw->flags = 0;
330 ccw->count = 0;
331 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
332 return ccw + 1;
333}
334
335static inline struct ccw1 *
336tape_ccw_repeat(struct ccw1 *ccw, __u8 cmd_code, int count)
337{
338 while (count-- > 0) {
339 ccw->cmd_code = cmd_code;
340 ccw->flags = CCW_FLAG_CC;
341 ccw->count = 0;
342 ccw->cda = (__u32)(addr_t) &ccw->cmd_code;
343 ccw++;
344 }
345 return ccw;
346}
347
348static inline struct ccw1 *
349tape_ccw_cc_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
350{
351 ccw->cmd_code = cmd_code;
352 ccw->flags = CCW_FLAG_CC;
353 idal_buffer_set_cda(idal, ccw);
354 return ccw++;
355}
356
357static inline struct ccw1 *
358tape_ccw_end_idal(struct ccw1 *ccw, __u8 cmd_code, struct idal_buffer *idal)
359{
360 ccw->cmd_code = cmd_code;
361 ccw->flags = 0;
362 idal_buffer_set_cda(idal, ccw);
363 return ccw++;
364}
365
366
367extern const char *tape_state_verbose[];
368extern const char *tape_op_verbose[];
369
370#endif
371