2 * tape device driver for 3480/3490E/3590 tapes.
4 * S390 and zSeries version
5 * Copyright IBM Corp. 2001, 2009
6 * Author(s): Carsten Otte <cotte@de.ibm.com>
7 * Tuan Ngo-Anh <ngoanh@de.ibm.com>
8 * Martin Schwidefsky <schwidefsky@de.ibm.com>
9 * Stefan Bader <shbader@de.ibm.com>
15 #include <asm/ccwdev.h>
16 #include <asm/debug.h>
17 #include <asm/idals.h>
18 #include <linux/blkdev.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>
28 * Define DBF_LIKE_HELL for lots of messages in the debug feature.
32 #define DBF_LH(level, str, ...) \
34 debug_sprintf_event(TAPE_DBF_AREA, level, str, ## __VA_ARGS__); \
37 #define DBF_LH(level, str, ...) do {} while(0)
41 * macros s390 debug feature (dbf)
43 #define DBF_EVENT(d_level, d_str...) \
45 debug_sprintf_event(TAPE_DBF_AREA, d_level, d_str); \
48 #define DBF_EXCEPTION(d_level, d_str...) \
50 debug_sprintf_exception(TAPE_DBF_AREA, d_level, d_str); \
53 #define TAPE_VERSION_MAJOR 2
54 #define TAPE_VERSION_MINOR 0
55 #define TAPE_MAGIC "tape"
57 #define TAPE_MINORS_PER_DEV 2 /* two minors per device */
58 #define TAPEBLOCK_HSEC_SIZE 2048
59 #define TAPEBLOCK_HSEC_S2B 2
60 #define TAPEBLOCK_RETRIES 5
62 enum tape_medium_state
{
79 TO_BLOCK
, /* Block read */
80 TO_BSB
, /* Backward space block */
81 TO_BSF
, /* Backward space filemark */
82 TO_DSE
, /* Data security erase */
83 TO_FSB
, /* Forward space block */
84 TO_FSF
, /* Forward space filemark */
85 TO_LBL
, /* Locate block label */
86 TO_NOP
, /* No operation */
87 TO_RBA
, /* Read backward */
88 TO_RBI
, /* Read block information */
89 TO_RFO
, /* Read forward */
90 TO_REW
, /* Rewind tape */
91 TO_RUN
, /* Rewind and unload tape */
92 TO_WRI
, /* Write block */
93 TO_WTM
, /* Write tape mark */
94 TO_MSEN
, /* Medium sense */
95 TO_LOAD
, /* Load tape */
96 TO_READ_CONFIG
, /* Read configuration data */
97 TO_READ_ATTMSG
, /* Read attention message */
98 TO_DIS
, /* Tape display */
99 TO_ASSIGN
, /* Assign tape to channel path */
100 TO_UNASSIGN
, /* Unassign tape from channel path */
101 TO_CRYPT_ON
, /* Enable encrpytion */
102 TO_CRYPT_OFF
, /* Disable encrpytion */
103 TO_KEKL_SET
, /* Set KEK label */
104 TO_KEKL_QUERY
, /* Query KEK label */
105 TO_RDC
, /* Read device characteristics */
106 TO_SIZE
, /* #entries in tape_op_t */
109 /* Forward declaration */
112 /* tape_request->status can be: */
113 enum 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. */
118 TAPE_REQUEST_CANCEL
, /* request should be canceled. */
119 TAPE_REQUEST_LONG_BUSY
, /* request has to be restarted after long busy */
122 /* Tape CCW request */
123 struct 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. */
133 /* Callback for delivering final status. */
134 void (*callback
)(struct tape_request
*, void *);
141 /* Function type for magnetic tape commands */
142 typedef int (*tape_mtop_fn
)(struct tape_device
*, int);
144 /* Size of the array containing the mtops for a discipline */
145 #define TAPE_NR_MTOPS (MTMKPART+1)
147 /* Tape Discipline */
148 struct 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 /* 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
;
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:
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 #define TAPE_IO_LONG_BUSY 4 /* delay the running request */
172 /* Char Frontend Data */
173 struct tape_char_data
{
174 struct idal_buffer
*idal_buf
; /* idal buffer for user char data */
175 int block_size
; /* of size block_size. */
180 /* entry in tape_device_list */
181 struct list_head node
;
184 struct ccw_device
* cdev
;
185 struct tape_class_device
* nt
;
186 struct tape_class_device
* rt
;
188 /* Device mutex to serialize tape commands. */
191 /* Device discipline information. */
192 struct tape_discipline
* discipline
;
195 /* Generic status flags */
196 long tape_generic_status
;
198 /* Device state information. */
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
;
204 /* Reference count. */
208 struct list_head req_queue
;
210 /* Request wait queue. */
211 wait_queue_head_t wait_queue
;
213 /* Each tape device has (currently) two minor numbers. */
216 /* Number of tapemarks required for correct termination. */
217 int required_tapemarks
;
219 /* Block ID of the BOF */
222 /* Character device frontend data */
223 struct tape_char_data char_data
;
225 /* Function to start or stop the next request later. */
226 struct delayed_work tape_dnr
;
228 /* Timer for long busy */
229 struct timer_list lb_timeout
;
233 /* Externals from tape_core.c */
234 extern struct tape_request
*tape_alloc_request(int cplength
, int datasize
);
235 extern void tape_free_request(struct tape_request
*);
236 extern int tape_do_io(struct tape_device
*, struct tape_request
*);
237 extern int tape_do_io_async(struct tape_device
*, struct tape_request
*);
238 extern int tape_do_io_interruptible(struct tape_device
*, struct tape_request
*);
239 extern int tape_cancel_io(struct tape_device
*, struct tape_request
*);
240 void tape_hotplug_event(struct tape_device
*, int major
, int action
);
243 tape_do_io_free(struct tape_device
*device
, struct tape_request
*request
)
247 rc
= tape_do_io(device
, request
);
248 tape_free_request(request
);
253 tape_do_io_async_free(struct tape_device
*device
, struct tape_request
*request
)
255 request
->callback
= (void *) tape_free_request
;
256 request
->callback_data
= NULL
;
257 tape_do_io_async(device
, request
);
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
);
267 extern int tape_generic_online(struct tape_device
*, struct tape_discipline
*);
268 extern int tape_generic_offline(struct ccw_device
*);
269 extern int tape_generic_pm_suspend(struct ccw_device
*);
271 /* Externals from tape_devmap.c */
272 extern int tape_generic_probe(struct ccw_device
*);
273 extern void tape_generic_remove(struct ccw_device
*);
275 extern struct tape_device
*tape_find_device(int devindex
);
276 extern struct tape_device
*tape_get_device(struct tape_device
*);
277 extern void tape_put_device(struct tape_device
*);
279 /* Externals from tape_char.c */
280 extern int tapechar_init(void);
281 extern void tapechar_exit(void);
282 extern int tapechar_setup_device(struct tape_device
*);
283 extern void tapechar_cleanup_device(struct tape_device
*);
285 /* tape initialisation functions */
286 #ifdef CONFIG_PROC_FS
287 extern void tape_proc_init (void);
288 extern void tape_proc_cleanup (void);
290 static inline void tape_proc_init (void) {;}
291 static inline void tape_proc_cleanup (void) {;}
294 /* a function for dumping device sense info */
295 extern void tape_dump_sense_dbf(struct tape_device
*, struct tape_request
*,
298 /* functions for handling the status of a device */
299 extern void tape_med_state_set(struct tape_device
*, enum tape_medium_state
);
302 extern debug_info_t
*TAPE_DBF_AREA
;
304 /* functions for building ccws */
305 static inline struct ccw1
*
306 tape_ccw_cc(struct ccw1
*ccw
, __u8 cmd_code
, __u16 memsize
, void *cda
)
308 ccw
->cmd_code
= cmd_code
;
309 ccw
->flags
= CCW_FLAG_CC
;
310 ccw
->count
= memsize
;
311 ccw
->cda
= (__u32
)(addr_t
) cda
;
315 static inline struct ccw1
*
316 tape_ccw_end(struct ccw1
*ccw
, __u8 cmd_code
, __u16 memsize
, void *cda
)
318 ccw
->cmd_code
= cmd_code
;
320 ccw
->count
= memsize
;
321 ccw
->cda
= (__u32
)(addr_t
) cda
;
325 static inline struct ccw1
*
326 tape_ccw_cmd(struct ccw1
*ccw
, __u8 cmd_code
)
328 ccw
->cmd_code
= cmd_code
;
331 ccw
->cda
= (__u32
)(addr_t
) &ccw
->cmd_code
;
335 static inline struct ccw1
*
336 tape_ccw_repeat(struct ccw1
*ccw
, __u8 cmd_code
, int count
)
338 while (count
-- > 0) {
339 ccw
->cmd_code
= cmd_code
;
340 ccw
->flags
= CCW_FLAG_CC
;
342 ccw
->cda
= (__u32
)(addr_t
) &ccw
->cmd_code
;
348 static inline struct ccw1
*
349 tape_ccw_cc_idal(struct ccw1
*ccw
, __u8 cmd_code
, struct idal_buffer
*idal
)
351 ccw
->cmd_code
= cmd_code
;
352 ccw
->flags
= CCW_FLAG_CC
;
353 idal_buffer_set_cda(idal
, ccw
);
357 static inline struct ccw1
*
358 tape_ccw_end_idal(struct ccw1
*ccw
, __u8 cmd_code
, struct idal_buffer
*idal
)
360 ccw
->cmd_code
= cmd_code
;
362 idal_buffer_set_cda(idal
, ccw
);
367 extern const char *tape_state_verbose
[];
368 extern const char *tape_op_verbose
[];
370 #endif /* for ifdef tape.h */