1/***************************************************************************
2 *
3 *  drivers/s390/char/tape.h
4 *    tape device driver for 3480/3490E tapes.
5 *
6 *  S390 and zSeries version
7 *    Copyright (C) 2001 IBM Corporation
8 *    Author(s): Carsten Otte <cotte@de.ibm.com>
9 *               Tuan Ngo-Anh <ngoanh@de.ibm.com>
10 *
11 ****************************************************************************
12 */
13
14#ifndef _TAPE_H
15
16#define _TAPE_H
17#include <linux/config.h>
18#include <linux/blkdev.h>
19
20#define  MAX_TAPES                     7        /* Max tapes supported is 7*/
21#define TAPE_MAGIC 0xE3C1D7C5       /* is ebcdic-"TAPE" */
22
23typedef enum {
24    TS_UNUSED=0, TS_IDLE, TS_DONE, TS_FAILED,
25    TS_BLOCK_INIT,
26    TS_BSB_INIT,
27    TS_BSF_INIT,
28    TS_DSE_INIT,
29    TS_EGA_INIT,
30    TS_FSB_INIT,
31    TS_FSF_INIT,
32    TS_LDI_INIT,
33    TS_LBL_INIT,
34    TS_MSE_INIT,
35    TS_NOP_INIT,
36    TS_RBA_INIT,
37    TS_RBI_INIT,
38    TS_RBU_INIT,
39    TS_RBL_INIT,
40    TS_RDC_INIT,
41    TS_RFO_INIT,
42    TS_RSD_INIT,
43    TS_REW_INIT,
44    TS_REW_RELEASE_INIT,
45    TS_RUN_INIT,
46    TS_SEN_INIT,
47    TS_SID_INIT,
48    TS_SNP_INIT,
49    TS_SPG_INIT,
50    TS_SWI_INIT,
51    TS_SMR_INIT,
52    TS_SYN_INIT,
53    TS_TIO_INIT,
54    TS_UNA_INIT,
55    TS_WRI_INIT,
56    TS_WTM_INIT,
57    TS_NOT_OPER,
58    TS_SIZE } tape_stat;
59
60struct _tape_info_t; //Forward declaration
61
62typedef enum {
63    TE_START=0, TE_DONE, TE_FAILED, TE_ERROR, TE_OTHER,
64    TE_SIZE } tape_events;
65
66typedef void (*tape_disc_shutdown_t) (int);
67typedef void (*tape_event_handler_t) (struct _tape_info_t*);
68typedef ccw_req_t* (*tape_ccwgen_t)(struct _tape_info_t* ti,int count);
69typedef ccw_req_t* (*tape_reqgen_t)(struct request* req,struct _tape_info_t* ti,int tapeblock_major);
70typedef ccw_req_t* (*tape_rwblock_t)(const char* data,size_t count,struct _tape_info_t* ti);
71typedef void (*tape_freeblock_t)(ccw_req_t* cqr,struct _tape_info_t* ti);
72typedef void (*tape_setup_assist_t) (struct _tape_info_t*);
73#ifdef CONFIG_DEVFS_FS
74typedef void (*tape_devfs_handler_t) (struct _tape_info_t*);
75#endif
76typedef tape_event_handler_t tape_event_table_t[TS_SIZE][TE_SIZE];
77typedef struct _tape_discipline_t {
78    unsigned int cu_type;
79    tape_setup_assist_t setup_assist;
80    tape_event_handler_t error_recovery;
81    tape_reqgen_t bread;
82    tape_freeblock_t free_bread;
83    tape_rwblock_t write_block;
84    tape_freeblock_t free_write_block;
85    tape_rwblock_t read_block;
86    tape_freeblock_t free_read_block;
87    tape_ccwgen_t mtfsf;
88    tape_ccwgen_t mtbsf;
89    tape_ccwgen_t mtfsr;
90    tape_ccwgen_t mtbsr;
91    tape_ccwgen_t mtweof;
92    tape_ccwgen_t mtrew;
93    tape_ccwgen_t mtoffl;
94    tape_ccwgen_t mtnop;
95    tape_ccwgen_t mtbsfm;
96    tape_ccwgen_t mtfsfm;
97    tape_ccwgen_t mteom;
98    tape_ccwgen_t mterase;
99    tape_ccwgen_t mtsetdensity;
100    tape_ccwgen_t mtseek;
101    tape_ccwgen_t mttell;
102    tape_ccwgen_t mtsetdrvbuffer;
103    tape_ccwgen_t mtlock;
104    tape_ccwgen_t mtunlock;
105    tape_ccwgen_t mtload;
106    tape_ccwgen_t mtunload;
107    tape_ccwgen_t mtcompression;
108    tape_ccwgen_t mtsetpart;
109    tape_ccwgen_t mtmkpart;
110    tape_ccwgen_t mtiocget;
111    tape_ccwgen_t mtiocpos;
112    tape_disc_shutdown_t shutdown;
113    int (*discipline_ioctl_overload)(struct inode *,struct file*, unsigned int,unsigned long);
114    tape_event_table_t* event_table;
115    tape_event_handler_t default_handler;
116    struct _tape_info_t* tape; /* pointer for backreference */
117    void* next;
118} tape_discipline_t  __attribute__ ((aligned(8)));
119
120typedef struct _tape_frontend_t {
121    tape_setup_assist_t device_setup;
122#ifdef CONFIG_DEVFS_FS
123    tape_devfs_handler_t mkdevfstree;
124    tape_devfs_handler_t rmdevfstree;
125#endif
126    void* next;
127} tape_frontend_t  __attribute__ ((aligned(8)));
128
129
130typedef struct _tape_info_t {
131    wait_queue_head_t wq;
132    s390_dev_info_t devinfo;             /* device info from Common I/O */
133    int     wanna_wakeup;
134    int     rew_minor;                  /* minor number for the rewinding tape */
135    int     nor_minor;                  /* minor number for the nonrewinding tape */
136    int     blk_minor;                  /* minor number for the block device */
137    devstat_t devstat;	           /* contains irq, devno, status */
138    size_t  block_size;             /* block size of tape        */
139    int    drive_type;              /* Code indicating type of drive */
140    struct file *rew_filp;	           /* backpointer to file structure */
141    struct file *nor_filp;
142    struct file *blk_filp;
143    int tape_state;  /* State of the device. See tape_stat */
144    int rc;          /* Return code. */
145    tape_discipline_t* discipline;
146    request_queue_t request_queue;
147    struct request* current_request;
148    int blk_retries;
149    long position;
150    int medium_is_unloaded;  // Becomes true when a unload-type operation was issued, false again when medium-insert was detected
151    ccw_req_t* cqr;
152    atomic_t bh_scheduled;
153    struct tq_struct bh_tq;
154#ifdef CONFIG_DEVFS_FS
155    devfs_handle_t devfs_dir;             /* devfs handle for tape/DEVNO directory */
156    devfs_handle_t devfs_char_dir;        /* devfs handle for tape/DEVNO/char directory */
157    devfs_handle_t devfs_block_dir;       /* devfs handle for tape/DEVNO/block directory */
158    devfs_handle_t devfs_nonrewinding;    /* devfs handle for tape/DEVNO/char/nonrewinding device */
159    devfs_handle_t devfs_rewinding;       /* devfs handle for tape/DEVNO/char/rewinding device */
160    devfs_handle_t devfs_disc;            /* devfs handle for tape/DEVNO/block/disc device */
161#endif
162    void* discdata;
163    void* kernbuf;
164    void* userbuf;
165    void*  next;
166} tape_info_t  __attribute__ ((aligned(8)));
167
168/* tape initialisation functions */
169int tape_init(void);
170int tape_setup (tape_info_t * ti, int irq, int minor);
171
172/* functoins for alloc'ing ccw stuff */
173inline  ccw_req_t * tape_alloc_ccw_req (tape_info_t* ti, int cplength, int datasize);
174void tape_free_request (ccw_req_t * request);
175
176/* a function for dumping device sense info */
177void tape_dump_sense (devstat_t * stat);
178
179#ifdef CONFIG_S390_TAPE_DYNAMIC
180/* functions for dyn. dev. attach/detach */
181int tape_oper_handler ( int irq, struct _devreg *dreg);
182#endif
183
184/* functions for handling the status of a device */
185inline void tapestate_set (tape_info_t * ti, int newstate);
186inline int tapestate_get (tape_info_t * ti);
187void tapestate_event (tape_info_t * ti, int event);
188extern char* state_verbose[TS_SIZE];
189extern char* event_verbose[TE_SIZE];
190
191/****************************************************************************/
192
193/* Some linked lists for storing plugins and devices */
194extern tape_info_t *first_tape_info;
195extern tape_discipline_t *first_discipline;
196extern tape_frontend_t *first_frontend;
197
198/* The debug area */
199#ifdef TAPE_DEBUG
200extern debug_info_t *tape_debug_area;
201#endif
202
203#endif /* for ifdef tape.h */
204