1/*	$NetBSD: mtreg.h,v 1.1.2.4 2005/03/04 16:41:14 skrll Exp $	*/
2
3/*
4 * Copyright (c) 1992, The University of Utah and
5 * the Computer Systems Laboratory at the University of Utah (CSL).
6 * All rights reserved.
7 *
8 * Permission to use, copy, modify and distribute this software is hereby
9 * granted provided that (1) source code retains these copyright, permission,
10 * and disclaimer notices, and (2) redistributions including binaries
11 * reproduce the notices in supporting documentation, and (3) all advertising
12 * materials mentioning features or use of this software display the following
13 * acknowledgement: ``This product includes software developed by the
14 * Computer Systems Laboratory at the University of Utah.''
15 *
16 * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
17 * IS" CONDITION.  THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
18 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 *
20 * CSL requests users of this software to return to csl-dist@cs.utah.edu any
21 * improvements that they make and grant CSL redistribution rights.
22 *
23 *	Utah $Hdr: mtreg.h 1.4 95/09/12$
24 */
25
26/*	@(#)mtreg.h	3.4	90/07/10	mt Xinu
27 *
28 *	Hewlett-Packard 7974, 7978, 7979 and 7980 HPIB Mag-Tape declarations.
29 */
30
31/*
32 *	Hardware Id's
33 */
34
35#define MT7974AID	0x174
36#define MT7978ID	0x178
37#define MT7979AID	0x179
38#define MT7980ID	0x180
39
40/* convert bytes to 1k tape block and back */
41#define CTBTOK(x)	((x) >> 10)
42#define CTKTOB(x)	((x) << 10)
43
44/*
45 *	Listen Secondary Commands
46 */
47
48#define MTL_WRITE	0	/* write execute */
49#define MTL_TCMD	1	/* tape command */
50#define MTL_DIAG	4	/* download diagnostic */
51#define MTL_FUP		6	/* write firmware update */
52#define MTL_ECMD	7	/* end command */
53#define MTL_DCL		16	/* amigo device clear */
54#define MTL_CCRC	17	/* clear CRC */
55#define MTL_XTEST	29	/* run 7979a/7980 extended self test */
56#define MTL_LOOP	30	/* write interface loopback */
57#define MTL_TEST	31	/* run self test */
58
59/*
60 *	Talk Secondary Commands
61 */
62
63#define MTT_READ	0	/* read execute */
64#define MTT_STAT	1	/* read status */
65#define MTT_BCNT	2	/* read byte count */
66#define MTT_DIAG	3	/* read diagnostic results */
67#define MTT_FREV	4	/* read firmware revisions (7980xc) */
68#define MTT_LOG		5	/* read diagnostic log */
69#define MTT_FUP		6	/* read firmware update */
70#define MTT_XSTAT	15	/* read extended status (7979a/7980a) */
71#define MTT_DSJ		16	/* read DSJ (device specified jump) */
72#define MTT_RCRC	17	/* read CRC */
73#define MTT_XTEST	29	/* read 7979a/7980 extended self test */
74#define MTT_LOOP	30	/* read interface loopback */
75#define MTT_TEST	31	/* read self test */
76
77/*
78 *	Tape commands
79 */
80
81#define MTTC_SEL0	0	/* Select Unit 0 (native protocol) */
82#define MTTC_WRITE	5	/* Write Record */
83#define MTTC_WFM	6	/* Write File Mark */
84#define MTTC_WGAP	7	/* Write Gap */
85#define MTTC_READ	8	/* Read record */
86#define MTTC_FSR	9	/* forward space record */
87#define MTTC_BSR	10	/* backward space record */
88#define MTTC_FSF	11	/* forward space file */
89#define MTTC_BSF	12	/* backward space file */
90#define MTTC_REW	13	/* rewind */
91#define MTTC_REWOFF	14	/* rewind and go offline */
92#define MTTC_DC6250	15	/* set data compressed 6250 */
93#define MTTC_6250	16	/* set 6250 bpi */
94#define MTTC_1600	17	/* set 1600 bpi */
95#define MTTC_800	18	/* set 800 bpi */
96#define MTTC_NC6250	19	/* set non-compressed 6250 */
97#define MTTC_STSTP	20	/* start/stop mode only */
98#define MTTC_STRM	21	/* enable streaming */
99#define MTTC_DIRM	22	/* disable immediate report mode */
100#define MTTC_EIRM	23	/* enable immediate report mode */
101#define MTTC_STAT	24	/* request status */
102#define MTTC_RLD	25	/* remote load */
103#define MTTC_RUNLD	26	/* remote unload */
104#define MTTC_RON	28	/* remote online */
105#define MTTC_DDC	30	/* disable data compression */
106#define MTTC_EDC	31	/* enable data compression */
107
108/*
109 *	End Command Bits (of any interest)
110 */
111#define	MTE_COMPLETE	0x08	/* "marks the end of the report phase" */
112#define	MTE_IDLE	0x04	/* enables parallel poll resp. for online */
113#define	MTE_STOP	0x02	/* aborts transfer of "read" data */
114
115#define	MTE_DSJ_FORCE	0x100	/* XXX During readDSJ, force a status fetch */
116
117
118struct	mt_stat {
119	u_char	m_stat[6];
120};
121
122/* sc_flags */
123#define	MTF_OPEN	0x0001	/* drive is in use (single-access device) */
124#define	MTF_EXISTS	0x0002	/* device was found at boot time */
125#define	MTF_ALIVE	0x0004	/* drive actually talks to us */
126#define	MTF_WRT		0x0008	/* last command was a WRITE */
127#define	MTF_IO		0x0010	/* next interrupt should start I/O (DMA) */
128#define	MTF_REW		0x0020	/* tape is rewinding - must wait for it */
129#define	MTF_HITEOF	0x0040	/* last read or FSR hit EOF (file mark) */
130#define	MTF_HITBOF	0x0080	/* last BSR hit EOF (file mark) */
131#define	MTF_ATEOT	0x0100	/* tape hit EOT - can allow one forward op */
132#define	MTF_PASTEOT	0x0200	/* tape is beyond EOT - force backward motion */
133#define	MTF_DSJTIMEO	0x0400	/* timed out gpibrecv()ing DSJ - continue it */
134#define	MTF_STATTIMEO	0x0800	/* timed out recieving STATUS - continue it */
135#define	MTF_STATCONT	0x1000	/* STATTIMEO is continuable */
136
137/* additional "mtcommand"s */
138#define MTRESET		16	/* reset the thing from scratch */
139#define MTSET800BPI	17	/* density select */
140#define MTSET1600BPI	18
141#define MTSET6250BPI	19
142#define MTSET6250DC	20	/* (data compressed - MT7980ID only) */
143
144/* status bytes */
145#define sc_stat1	sc_stat.m_stat[0]
146#define sc_stat2	sc_stat.m_stat[1]
147#define sc_stat3	sc_stat.m_stat[2]
148#define sc_stat4	sc_stat.m_stat[3]
149#define sc_stat5	sc_stat.m_stat[4]
150#define sc_stat6	sc_stat.m_stat[5]
151
152/*
153 *	Status Register definitions
154 */
155
156#define	SR1_EOF		0x80	/* positioned at File Mark */
157#define	SR1_BOT		0x40	/* positioned at Beginning of Tape */
158#define	SR1_EOT		0x20	/* positioned at End of Tape */
159#define	SR1_SOFTERR	0x10	/* Recoverable Error has Occurred */
160#define	SR1_REJECT	0x08	/* HPIB Cmd rejected - Regs 4 & 5 have info */
161#define	SR1_RO		0x04	/* No Write Ring */
162#define	SR1_ERR		0x02	/* Unrecoverable Data error - Reg 5 has info */
163#define	SR1_ONLINE	0x01	/* Drive Online (must be to do any operation) */
164
165#define	SR2_6250	0x80	/* tape is 6250BPI */
166#define	SR2_UNKDEN	0x40	/* non-blank tape is of unknown density */
167#define	SR2_PARITY	0x20	/* internal bus data parity error detected */
168#define	SR2_OVERRUN	0x10	/* data buffer overrun (not possible?) */
169#define	SR2_RUNAWAY	0x08	/* during read, no data detected on tape */
170#define	SR2_OPEN	0x04	/* tape door is open */
171#define	SR2_LONGREC	0x02	/* large record support (32k@1600, 60K@6250,
172				   otherwise, it's 16K at all densities) */
173#define	SR2_IMMED	0x01	/* Immediate Response (for writes) enabled */
174
175#define	SR3_1600	0x80	/* tape is 1600BPI */
176#define	SR3_800		0x40	/* tape is 800BPI */
177#define	SR3_POWERUP	0x20	/* power recently restored or Dev Clr done */
178#define	SR3_HPIBPAR	0x10	/* HPIB command parity error detected */
179#define	SR3_LOST	0x08	/* position on tape is unknown */
180#define	SR3_FMTERR	0x04	/* formatter error - Reg 5 has info */
181#define	SR3_SVOERR	0x02	/* motion servo error - Reg 4 has info */
182#define	SR3_CTLERR	0x01	/* controller error - Reg 5 has info */
183
184#define SR4_ERCLMASK	0xe0	/* Mask of error classes (for SR1_REJECT) */
185#define SR4_NONE	0x00
186#define SR4_DEVICE	0x40
187#define SR4_PROTOCOL	0x60
188#define SR4_SELFTEST	0xe0
189#define	SR4_RETRYMASK	0x1f	/* Mask for retry count (for any error) */
190
191/* SR5 holds lots of error codes, referenced above.  Complete list:
192 * (DEVICE REJECT)
193 *	  5	Tape is write protected
194 *	  6	Tape isn't loaded
195 *	  7	Requested density not supported
196 *	  9	Tape being read is unreadable
197 *	 10	Tape being written is unidentifiable
198 *	 11	Drive offline
199 *	 16	Changing density while not at BOT
200 *	 19	Backward motion requested while at BOT
201 *	 23	Protocol out of sync
202 *	 24	Unknown tape command
203 *	 31	Write request too big for drive/density
204 *	 32	Beyond EOT
205 *	 33	Self Test Failure
206 *	 37	Tape positioning failure while removing readaheads
207 *	 40	Door open
208 * (UNRECOVERED DATA/FORMAT ERRORS)
209 *	 41	Tape velocity out of spec
210 *	 45	Multiple track data error
211 *	 47	Write verify failed
212 *	 48	Noise found while trying to detect data record
213 *	 49	Data format error
214 *	 50	Couldn't identify tape after rewind
215 *	 51	Gap detected before end of data record
216 *	 52	Data block dropout
217 *	 53	CRC error
218 *	 54	Parity error
219 *	 55	Door open
220 *	 57	Maximum skew exceeded
221 *	 58	False data block detected
222 *	 59	Corrected data error on write
223 *	 60	Buffer overrun - record size on tape larger than supported
224 *	 61	Data block timeout (possibly record length too long)
225 *	 62	Tape mark dropout
226 *	 63	Tape mark unverified
227 *	 64	Tape mark timeout (no gap following tape mark)
228 * (POSITION or SERVO ERRORS) - these are ALL internal to tape drive
229 *	 81	Servo unresponsive
230 *	 82	Servo didn't respond with corect state
231 *	 83	Servo shutdown
232 *	 84	Servo detected hardware failure
233 *	 85	Servo protocol error
234 *	 86	Runtime Servo error
235 *	 87	Missing position interrupt
236 *	 88	No Gap after read or write
237 *	 89	Motor shutdown for safety reasons
238 *	 90	Couldn't find tape BOT mark
239 *	 91	Drive motor running too fast or slow
240 *	 92	Requested controller state invalid within context
241 *	 94	Tape positioning failure
242 * (FORMATTER ERROR)
243 *	101,108	Read formatter unresponsive
244 *	102,107	Read formatter hardware error
245 *	103	Write detected bad block
246 *	104	Erase failure
247 *	105	No data detected after write
248 *	106	Tracks out of sync on write verify
249 *	109	No gap timeout
250 *	110	Formatter <--> data buffer byte count mismatch
251 * (CONTROLLER ERROR) - these are ALL internal to drive
252 *	121	Transaction ID mismatch (device vs. controller)
253 *	122	Devoce report has no coorepinding command
254 *	123	Invalid device report
255 *	124	Repost queue overflow
256 *	125	Unknown command from device
257 *	126	Command queue overflow
258 *	128	Missing End-Of-Record flag in data buffer
259 *	129	Data buffer parity error
260 *	130	Data buffer underrun during write
261 *	131	Byte count mismatch in data buffer queue
262 *	132	Bad message type from device
263 *	133	Abort between HPIB interface and channel program
264 *	134	Unknown HPIB interface exception
265 *	137	Illegal access to servo conntroller registers
266 *	138	Device program firmware error
267 *	139	Hardware utilities firmware error
268 *	140	Channel program firmware error
269 *	141	Encoder inoperative
270 *	150	Tape position synchronization error
271 *	151	Tape deblocking error (Xtra Capacity only)
272 *	152	Compression/Decompression hardware error (Xtra Capacity only)
273 * (PROTOCOL ERROR) - USUALLY indicates deficiency in driver
274 *	161	No room in Command Queue
275 *	162	Expected "request DSJ"
276 *	163	Expected status request
277 *	165	Unknown unit select
278 *	166	Tape command secondary expected
279 *	167	Data byte expected
280 *	168	Missing EOI on data byte
281 *	170	Write command phase protocol error
282 *	172	Read record report phase error
283 *	173	Report phase protocol error
284 *	174	Cold load sequence error
285 *	175	HPIB protocol sequence error
286 *	176	END command expected
287 *	178	END DATA expected
288 *	180	Unknown interface secondary command
289 *	181	Misplaced data byte
290 *	184	Interface Loopback protocol error
291 *	185	Self test protocol error
292 *	188	HPIB parity error
293 *	189	Operator reset during protocol sequence
294 *	190	Device clear received
295 */
296
297/* SR6 is count of commands accepted since Immediate Response command failed */
298