1 /* $Id: tpqic02.h,v 0.16 1993/04/19 23:15:39 root Exp root $
2 *
3 * Include file for QIC-02 driver for Linux.
4 *
5 * Copyright (c) 1992 by H. H. Bergman. All rights reserved.
6 *
7 * ******* USER CONFIG SECTION BELOW *******
8 */
9
10 #ifndef _LINUX_TPQIC02_H
11 #define _LINUX_TPQIC02_H
12
13 #include <linux/config.h>
14
15 #if CONFIG_TAPE_QIC02
16
17 /* need to have TAPE_QIC02_DRIVE and TAPE_QIC02_IFC expand to something */
18 #include <linux/mtio.h>
19
20
21 /* make TAPE_QIC02_IFC expand to something */
22 #define WANGTEK 1 /* don't know about Wangtek QIC-36 */
23 #define EVEREX WANGTEK /* I heard *some* of these are identical */
24 #define EVEREX_811V EVEREX /* With TEAC MT 2ST 45D */
25 #define EVEREX_831V EVEREX
26 #define ARCHIVE 3
27 #define ARCHIVE_SC400 ARCHIVE /* rumoured to be from the pre-SMD-age */
28 #define ARCHIVE_SC402 ARCHIVE /* don't know much about SC400 */
29 #define ARCHIVE_SC499 ARCHIVE /* SC402 and SC499R should be identical */
30
31
32 /*********** START OF USER CONFIGURABLE SECTION ************/
33
34 /* Tape configuration:
35 *
36 * Tape drive configuration: (MT_IS* constants are defined in sys/mtio.h)
37 *
38 * TAPE_QIC02_DRIVE = MT_ISWT5150
39 * - Wangtek 5150, format: up to QIC-150.
40 * TAPE_QIC02_DRIVE = MT_ISQIC02_ALL_FEATURES
41 * - Enables some optional QIC commands that some drives may lack.
42 * It is provided so you can check which are supported by your drive.
43 * Refer to tpqic02.h for others.
44 *
45 * Supported interface cards: TAPE_QIC02_IFC =
46 * WANGTEK,
47 * ARCHIVE_SC402, ARCHIVE_SC499. (both same programming interface)
48 *
49 * Make sure you have the I/O ports/DMA channels
50 * and IRQ stuff configured properly!
51 * NOTE: Check for conflicts with TAPE_QIC02_TIMER in timer.h.
52 */
53
54 #define TAPE_QIC02_DRIVE MT_ISQIC02_ALL_FEATURES /* drive type */
55 /* #define TAPE_QIC02_DRIVE MT_ISWT5150 */
56 #define TAPE_QIC02_IFC WANGTEK /* interface card type */
57 /* #define TAPE_QIC02_IFC ARCHIVE */
58 #define TAPE_QIC02_PORT 0x300 /* controller port adress */
59 #define TAPE_QIC02_IRQ 5 /* Muhammad, please don't use 2 here. -- Hennus */
60 #define TAPE_QIC02_DMA 1 /* either 1 or 3, because 2 is used by the floppy */
61
62
63 /************ END OF USER CONFIGURABLE SECTION *************/
64
65
66 /* NOTE: TP_HAVE_DENS should distinguish between available densities
67 * NOTE: Drive select is not implemented -- I have only one tape streamer,
68 * so I'm unable and unmotivated to test and implement that. ;-) ;-)
69 */
70 #if TAPE_QIC02_DRIVE == MT_ISWT5150
71 #define TP_HAVE_DENS
72 #define TP_HAVE_BSF /* nope */
73 #define TP_HAVE_FSR /* nope */
74 #define TP_HAVE_BSR /* nope */
75 #define TP_HAVE_EOD /* most of the time */
76 #define TP_HAVE_RAS1
77 #define TP_HAVE_RAS2
78
79 #elif TAPE_QIC02_DRIVE == MT_ISARCHIVESC499 /* Archive SC-499 QIC-36 controller */
80 #define TP_HAVE_DENS /* can do set density (QIC-11 / QIC-24) */
81 #define TP_HAVE_FSR /* can skip one block forwards */
82 #define TP_HAVE_BSR /* can skip one block backwards */
83 #define TP_HAVE_EOD /* can seek to end of recorded data */
84 #define TP_HAVE_RAS1 /* can run selftest 1 */
85 #define TP_HAVE_RAS2 /* can run selftest 2 */
86 /* These last two selftests shouldn't be used yet! */
87
88 #elif (TAPE_QIC02_DRIVE == MT_ISARCHIVE_2060L) || (TAPE_QIC02_DRIVE == MT_ISARCHIVE_2150L)
89 #define TP_HAVE_DENS /* can do set density (QIC-24 / QIC-120 / QIC-150) */
90 #define TP_HAVE_FSR /* can skip one block forwards */
91 #define TP_HAVE_BSR /* can skip one block backwards */
92 #define TP_HAVE_EOD /* can seek to end of recorded data */
93 #define TP_HAVE_TELL /* can read current block address */
94 #define TP_HAVE_SEEK /* can seek to block */
95 #define TP_HAVE_RAS1 /* can run selftest 1 */
96 #define TP_HAVE_RAS2 /* can run selftest 2 */
97 /* These last two selftests shouldn't be used yet! */
98
99 #elif TAPE_QIC02_DRIVE == MT_ISQIC02_ALL_FEATURES
100 #define TP_HAVE_DENS /* can do set density */
101 #define TP_HAVE_BSF /* can search filemark backwards */
102 #define TP_HAVE_FSR /* can skip one block forwards */
103 #define TP_HAVE_BSR /* can skip one block backwards */
104 #define TP_HAVE_EOD /* can seek to end of recorded data */
105 #define TP_HAVE_SEEK /* seek to block address */
106 #define TP_HAVE_TELL /* tell current block address */
107 #define TP_HAVE_RAS1 /* can run selftest 1 */
108 #define TP_HAVE_RAS2 /* can run selftest 2 */
109 /* These last two selftests shouldn't be used yet! */
110
111
112 #else
113 #error No QIC-02 tape drive type defined!
114 /* If your drive is not listed above, first try the 'ALL_FEATURES',
115 * to see what commands are supported, then create your own entry in
116 * the list above. You may want to mail it to me, so that I can include
117 * it in the next release.
118 */
119 #endif
120
121
122 /* NR_BLK_BUF is a `tuneable parameter'. If you're really low on
123 * kernel space, you could decrease it to 1, or if you got a very
124 * slow machine, you could increase it up to 128 blocks. Less kernel
125 * buffer blocks result in more context-switching.
126 */
127 #define NR_BLK_BUF 20 /* max 128 blocks */
128 #define TAPE_BLKSIZE 512 /* streamer tape block size (fixed) */
129 #define TPQBUF_SIZE (TAPE_BLKSIZE*NR_BLK_BUF) /* buffer size */
130
131
132 #define BLOCKS_BEYOND_EW 2 /* nr of blocks after Early Warning hole */
133
134 #if TAPE_QIC02_IFC == WANGTEK
135 /* Wangtek interface card port locations */
136 # define QIC_STAT_PORT TAPE_QIC02_PORT
137 # define QIC_CTL_PORT TAPE_QIC02_PORT
138 # define QIC_CMD_PORT (TAPE_QIC02_PORT+1)
139 # define QIC_DATA_PORT (TAPE_QIC02_PORT+1)
140
141 /* status register bits (Active LOW!) */
142 # define QIC_STAT_READY 0x01
143 # define QIC_STAT_EXCEPTION 0x02
144 # define QIC_STAT_MASK (QIC_STAT_READY|QIC_STAT_EXCEPTION)
145
146 # define QIC_STAT_RESETMASK 0x07
147 # define QIC_STAT_RESETVAL (QIC_STAT_RESETMASK & ~QIC_STAT_EXCEPTION)
148
149 /* controller register (QIC_CTL_PORT) bits */
150 # define WT_CTL_ONLINE 0x01
151 # define QIC_CTL_RESET 0x02
152 # define QIC_CTL_REQUEST 0x04
153 # define WT_CTL_CMDOFF 0xC0
154 # if TAPE_QIC02_DMA == 3 /* dip-switches alone don't seem to cut it */
155 # define WT_CTL_DMA 0x10 /* enable dma chan3 */
156 # elif TAPE_QIC02_DMA == 1
157 # define WT_CTL_DMA 0x08 /* enable dma chan1 or chan2 */
158 # else
159 # error Unsupported or incorrect DMA configuration.
160 # endif
161
162 #elif TAPE_QIC02_IFC == ARCHIVE
163 /* Archive interface card port locations */
164 # define QIC_STAT_PORT (TAPE_QIC02_PORT+1)
165 # define QIC_CTL_PORT (TAPE_QIC02_PORT+1)
166 # define QIC_CMD_PORT (TAPE_QIC02_PORT)
167 # define QIC_DATA_PORT (TAPE_QIC02_PORT)
168 # define AR_START_DMA_PORT (TAPE_QIC02_PORT+2)
169 # define AR_RESET_DMA_PORT (TAPE_QIC02_PORT+3)
170
171 /* STAT port bits */
172 # define AR_STAT_IRQF 0x80 /* active high, interrupt request flag */
173 # define QIC_STAT_READY 0x40 /* active low */
174 # define QIC_STAT_EXCEPTION 0x20 /* active low */
175 # define QIC_STAT_MASK (QIC_STAT_READY|QIC_STAT_EXCEPTION)
176 # define AR_STAT_DMADONE 0x10 /* active high, DMA done */
177 # define AR_STAT_DIRC 0x08 /* active high, direction */
178
179 # define QIC_STAT_RESETMASK 0x70 /* check RDY,EXC,DMADONE */
180 # define QIC_STAT_RESETVAL ((QIC_STAT_RESETMASK & ~AR_STAT_IRQF & ~QIC_STAT_EXCEPTION) | AR_STAT_DMADONE)
181
182 /* CTL port bits */
183 # define QIC_CTL_RESET 0x80 /* drive reset */
184 # define QIC_CTL_REQUEST 0x40 /* notify of new command */
185 # define AR_CTL_IEN 0x20 /* interrupt enable */
186 # define AR_CTL_DNIEN 0x10 /* done-interrupt enable */
187 /* Note: All of these bits are cleared automatically when writing to
188 * AR_RESET_DMA_PORT. So AR_CTL_IEN and AR_CTL_DNIEN must be
189 * reprogrammed before the write to AR_START_DMA_PORT.
190 */
191
192 # if TAPE_QIC02_DMA > 3 /* channel 2 is used by the floppy driver */
193 # error DMA channels other than 1 and 3 are not supported.
194 # endif
195
196 #else
197 # error No valid interface card specified!
198 #endif /* TAPE_QIC02_IFC */
199
200 /* Standard QIC-02 commands -- rev F. All QIC-02 drives must support these */
201 #define QCMD_SEL_1 0x01 /* select drive 1 */
202 #define QCMD_SEL_2 0x02 /* select drive 2 */
203 #define QCMD_SEL_3 0x04 /* select drive 3 */
204 #define QCMD_SEL_4 0x08 /* select drive 4 */
205 #define QCMD_REWIND 0x21 /* rewind tape*/
206 #define QCMD_ERASE 0x22 /* erase tape */
207 #define QCMD_RETEN 0x24 /* retension tape */
208 #define QCMD_WRT_DATA 0x40 /* write data */
209 #define QCMD_WRT_FM 0x60 /* write file mark */
210 #define QCMD_RD_DATA 0x80 /* read data */
211 #define QCMD_RD_FM 0xA0 /* read file mark (forward direction) */
212 #define QCMD_RD_STAT 0xC0 /* read status */
213
214 /* Other (optional/vendor unique) commands */
215 /* Density commands are only valid when TP_BOM is set! */
216 #define QCMD_DENS_11 0x26 /* QIC-11 */
217 #define QCMD_DENS_24 0x27 /* QIC-24: 9 track 60MB */
218 #define QCMD_DENS_120 0x28 /* QIC-120: 15 track 120MB */
219 #define QCMD_DENS_150 0x29 /* QIC-150: 18 track 150MB */
220 #define QCMD_DENS_300 0x2A /* QIC-300/QIC-2100 */
221 #define QCMD_DENS_600 0x2B /* QIC-600/QIC-2200 */
222 /* don't know about QIC-1000 and QIC-1350 */
223
224 #define QCMD_WRTNU_DATA 0x40 /* write data, no underruns, insert filler. */
225 #define QCMD_SPACE_FWD 0x81 /* skip next block */
226 #define QCMD_SPACE_BCK 0x89 /* move tape head one block back -- very useful! */
227 #define QCMD_RD_FM_BCK 0xA8 /* read filemark (backwards) */
228 #define QCMD_SEEK_EOD 0xA3 /* skip to EOD */
229 #define QCMD_RD_STAT_X1 0xC1 /* read extended status 1 */
230 #define QCMD_RD_STAT_X2 0xC4 /* read extended status 2 */
231 #define QCMD_RD_STAT_X3 0xE0 /* read extended status 3 */
232 #define QCMD_SELF_TST1 0xC2 /* run self test 1 (nondestructive) */
233 #define QCMD_SELF_TST2 0xCA /* run self test 2 (destructive) */
234
235
236
237 /* "Vendor Unique" codes */
238 #if defined(MT_ISARCHIVESC499) || defined(MT_ISARCHIVE_2150L)
239 # define QCMDV_TELL_BLK 0xAE /* read current block address */
240 # define QCMDV_SEEK_BLK 0xAD /* seek to specific block */
241 # define SEEK_BUF_SIZE 3 /* address is 3 bytes */
242 #endif
243
244
245 /* Optional, QFA (Quick File Access) commands.
246 * Not all drives support this, but those that do could use these commands
247 * to implement semi-non-sequential access. `mt fsf` would benefit from this.
248 * QFA divides the tape into 2 partitions, a data and a directory partition,
249 * causing some incompatibility problems wrt std QIC-02 data exchange.
250 * It would be useful to cache the directory info, but that might be tricky
251 * to do in kernel-space. [Size constraints.]
252 * Refer to QIC-02, appendix A for more information.
253 * I have no idea how other *nix variants implement QFA.
254 * I have no idea which drives support QFA and which don't.
255 */
256 #define QFA_ENABLE 0x2D /* enter QFA mode, give @ BOT only */
257 #define QFA_DATA 0x20 /* select data partition */
258 #define QFA_DIR 0x23 /* select directory partition */
259 #define QFA_RD_POS 0xCF /* read position+status bytes */
260 #define QFA_SEEK_EOD 0xA1 /* seek EOD within current partition */
261 #define QFA_SEEK_BLK 0xAF /* seek to a block within current partition */
262
263
264
265 /* Minor device codes for tapes:
266 * |7|6|5|4|3|2|1|0|
267 * | \ | / \ | / |_____ 1=rewind on close, 0=no rewind on close
268 * | \|/ |_________ Density: 000=none, 001=QIC-11, 010=24, 011=120,
269 * | | 100=QIC-150, 101..111 reserved.
270 * | |_______________ Reserved for unit numbers.
271 * |___________________ Reserved for diagnostics during debugging.
272 */
273
274 #define TP_REWCLOSE(d) ((MINOR(d)&0x01) == 1) /* rewind bit */
275 /* rewind is only done if data has been transfered */
276 #define TP_DENS(dev) ((MINOR(dev) >> 1) & 0x07) /* tape density */
277 #define TP_UNIT(dev) ((MINOR(dev) >> 4) & 0x07) /* unit number */
278 #define TP_DIAGS(dev) (MINOR(dev) & 0x80) /* print excessive diagnostics */
279
280
281 /* status codes returned by a WTS_RDSTAT call */
282 struct tpstatus { /* sizeof(short)==2), LSB first */
283 unsigned short exs; /* Drive exception flags */
284 unsigned short dec; /* data error count: nr of blocks rewritten/soft read errors */
285 unsigned short urc; /* underrun count: nr of times streaming was interrupted */
286 };
287 #define TPSTATSIZE sizeof(struct tpstatus)
288
289
290 /* defines for tpstatus.exs -- taken from 386BSD wt driver */
291 #define TP_POR 0x100 /* Power on or reset occurred */
292 #define TP_EOR 0x200 /* REServed for end of RECORDED media */
293 #define TP_PAR 0x400 /* REServed for bus parity */
294 #define TP_BOM 0x800 /* Beginning of media */
295 #define TP_MBD 0x1000 /* Marginal block detected */
296 #define TP_NDT 0x2000 /* No data detected */
297 #define TP_ILL 0x4000 /* Illegal command */
298 #define TP_ST1 0x8000 /* Status byte 1 flag */
299 #define TP_FIL 0x01 /* File mark detected */
300 #define TP_BNL 0x02 /* Bad block not located */
301 #define TP_UDA 0x04 /* Unrecoverable data error */
302 #define TP_EOM 0x08 /* End of media */
303 #define TP_WRP 0x10 /* Write protected cartridge */
304 #define TP_USL 0x20 /* Unselected drive */
305 #define TP_CNI 0x40 /* Cartridge not in place */
306 #define TP_ST0 0x80 /* Status byte 0 flag */
307
308 #define REPORT_ERR0 (TP_CNI|TP_USL|TP_WRP|TP_EOM|TP_UDA|TP_BNL|TP_FIL)
309 #define REPORT_ERR1 (TP_ILL|TP_NDT|TP_MBD|TP_PAR)
310
311
312 #define EXC_UNKNOWN 0 /* (extra) Unknown exception code */
313 #define EXC_NCART 1 /* No cartridge */
314 #define EXC_NDRV 2 /* No drive */
315 #define EXC_WP 3 /* Write protected */
316 #define EXC_EOM 4 /* EOM */
317 #define EXC_RWA 5 /* read/write abort */
318 #define EXC_XBAD 6 /* read error, bad block transfered */
319 #define EXC_XFILLER 7 /* read error, filler block transfered */
320 #define EXC_NDT 8 /* read error, no data */
321 #define EXC_NDTEOM 9 /* read error, no data & EOM */
322 #define EXC_NDTBOM 10 /* read error, no data & BOM */
323 #define EXC_FM 11 /* Read a filemark */
324 #define EXC_ILL 12 /* Illegal command */
325 #define EXC_POR 13 /* Power on/reset */
326 #define EXC_MARGINAL 14 /* Marginal block detected */
327 #define EXC_EOR 15 /* (extra, for SEEKEOD) End Of Recorded data reached */
328 #define EXC_BOM 16 /* (extra) BOM reached */
329
330
331 #define TAPE_NOTIFY_TIMEOUT 1000000
332
333 /* internal function return codes */
334 #define TE_OK 0 /* everything is fine */
335 #define TE_EX 1 /* exception detected */
336 #define TE_ERR 2 /* some error */
337 #define TE_NS 3 /* can't read status */
338 #define TE_TIM 4 /* timed out */
339 #define TE_DEAD 5 /* tape drive doesn't respond */
340 #define TE_END 6 /******** Archive hack *****/
341
342 /* timeout timer values -- check these! */
343 #define TIM_S (4*HZ) /* 4 seconds (normal cmds) */
344 #define TIM_M (30*HZ) /* 30 seconds (write FM) */
345 #define TIM_R (8*60*HZ) /* 8 minutes (retensioning) */
346 #define TIM_F (2*3600*HZ) /* est. 1.2hr for full tape read/write+2 retens */
347
348 #define TIMERON(t) timer_table[TAPE_QIC02_TIMER].expires = jiffies + (t); \
349 timer_active |= (1<<TAPE_QIC02_TIMER)
350 #define TIMEROFF timer_active &= ~(1<<TAPE_QIC02_TIMER)
351 #define TIMERCONT timer_active |= (1<<TAPE_QIC02_TIMER)
352
353
354 typedef char flag;
355 #define NO 0 /* NO must be 0 */
356 #define YES 1 /* YES must be != 0 */
357
358
359 #ifdef TDEBUG
360 # define TPQDEB(s) s
361 # define TPQPUTS(s) tpqputs(s)
362 #else
363 # define TPQDEB(s)
364 # define TPQPUTS(s)
365 #endif
366
367
368
369 extern long tape_qic02_init(long); /* for kernel/mem.c */
370
371
372 #endif /* CONFIG_TAPE_QIC02 */
373
374 #endif /* _LINUX_TPQIC02_H */