xref: /netbsd-src/sys/arch/hp300/stand/common/scsireg.h (revision aaf4ece63a859a04e37cf3a7229b5fab0157cc06)
1 /*	$NetBSD: scsireg.h,v 1.2 2005/12/11 12:17:19 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Van Jacobson of Lawrence Berkeley Laboratory.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)scsireg.h	8.1 (Berkeley) 6/10/93
39  */
40 
41 /*
42  * HP 98265A SCSI Interface Hardware Description.
43  */
44 
45 struct scsidevice {
46 	u_char	p0,  scsi_id;
47 #define			ID_MASK		0x1f
48 #define			SCSI_ID		0x07
49 #define			ID_WORD_DMA	0x20
50 	u_char	p2,  scsi_csr;
51 #define			CSR_IE		0x80
52 #define			CSR_IR		0x40
53 #define			SCSI_IPL(csr)	((((csr)>>4)&3)+3)
54 #define			CSR_DMA32	0x08
55 #define			CSR_DMAIN	0x04
56 #define			CSR_DE1		0x02
57 #define			CSR_DE0		0x01
58 	u_char	p4,  scsi_wrap;
59 #define			WRAP_REQ	0x80
60 #define			WRAP_ACK	0x40
61 #define			WRAP_BSY	0x08
62 #define			WRAP_MSG	0x04
63 #define			WRAP_CD		0x02
64 #define			WRAP_IO		0x01
65 	u_char	p6,  scsi_hconf;
66 #define			HCONF_TP	0x80
67 #define			SCSI_SYNC_XFER(hconf) (((hconf)>>5)&3)
68 #define			HCONF_SD	0x10
69 #define			HCONF_PARITY	0x08
70 	u_char	p8[24];
71 	u_char	p32, scsi_bdid;
72 	u_char	p34, scsi_sctl;
73 #define			SCTL_DISABLE	0x80
74 #define			SCTL_CTRLRST	0x40
75 #define			SCTL_DIAG	0x20
76 #define			SCTL_ABRT_ENAB	0x10
77 #define			SCTL_PARITY_ENAB 0x08
78 #define			SCTL_SEL_ENAB	0x04
79 #define			SCTL_RESEL_ENAB	0x02
80 #define			SCTL_INTR_ENAB	0x01
81 	u_char	p36, scsi_scmd;
82 #define			SCMD_RST	0x10
83 #define			SCMD_ICPT_XFR	0x08
84 #define			SCMD_PROG_XFR	0x04
85 #define			SCMD_PAD	0x01	/* if initiator */
86 #define			SCMD_PERR_STOP	0x01	/* if target */
87 			/* command codes */
88 #define			SCMD_BUS_REL	0x00
89 #define			SCMD_SELECT	0x20
90 #define			SCMD_RST_ATN	0x40
91 #define			SCMD_SET_ATN	0x60
92 #define			SCMD_XFR	0x80
93 #define			SCMD_XFR_PAUSE	0xa0
94 #define			SCMD_RST_ACK	0xc0
95 #define			SCMD_SET_ACK	0xe0
96 	u_char	p38, scsi_tmod;
97 #define			TMOD_SYNC	0x80
98 	u_char	p40, scsi_ints;
99 #define			INTS_SEL	0x80
100 #define			INTS_RESEL	0x40
101 #define			INTS_DISCON	0x20
102 #define			INTS_CMD_DONE	0x10
103 #define			INTS_SRV_REQ	0x08
104 #define			INTS_TIMEOUT	0x04
105 #define			INTS_HARD_ERR	0x02
106 #define			INTS_RST	0x01
107 	u_char	p42, scsi_psns;
108 #define			PSNS_REQ	0x80
109 #define			PSNS_ACK	0x40
110 #define			PSNS_ATN	0x20
111 #define			PSNS_SEL	0x10
112 #define			PSNS_BSY	0x08
113 	u_char	p44, scsi_ssts;
114 #define			SSTS_INITIATOR	0x80
115 #define			SSTS_TARGET	0x40
116 #define			SSTS_BUSY	0x20
117 #define			SSTS_XFR	0x10
118 #define			SSTS_ACTIVE	(SSTS_INITIATOR|SSTS_XFR)
119 #define			SSTS_RST	0x08
120 #define			SSTS_TCZERO	0x04
121 #define			SSTS_DREG_FULL	0x02
122 #define			SSTS_DREG_EMPTY	0x01
123 	u_char	p46, scsi_serr;
124 #define			SERR_SCSI_PAR	0x80
125 #define			SERR_SPC_PAR	0x40
126 #define			SERR_TC_PAR	0x08
127 #define			SERR_PHASE_ERR	0x04
128 #define			SERR_SHORT_XFR	0x02
129 #define			SERR_OFFSET	0x01
130 	u_char	p48, scsi_pctl;
131 #define			PCTL_BFINT_ENAB	0x80
132 	u_char	p50, scsi_mbc;
133 	u_char	p52, scsi_dreg;
134 	u_char	p54, scsi_temp;
135 	u_char	p56, scsi_tch;
136 	u_char	p58, scsi_tcm;
137 	u_char	p60, scsi_tcl;
138 	u_char	p62, scsi_exbf;
139 };
140 
141 /* psns/pctl phase lines as bits */
142 #define	PHASE_MSG	0x04
143 #define	PHASE_CD	0x02		/* =1 if 'command' */
144 #define	PHASE_IO	0x01		/* =1 if data inbound */
145 /* Phase lines as values */
146 #define	PHASE		0x07		/* mask for psns/pctl phase */
147 #define	DATA_OUT_PHASE	0x00
148 #define	DATA_IN_PHASE	0x01
149 #define	CMD_PHASE	0x02
150 #define	STATUS_PHASE	0x03
151 #define	BUS_FREE_PHASE	0x04
152 #define	ARB_SEL_PHASE	0x05	/* Fuji chip combines arbitration with sel. */
153 #define	MESG_OUT_PHASE	0x06
154 #define	MESG_IN_PHASE	0x07
155 
156 /* SCSI Messages */
157 
158 #define	MSG_CMD_COMPLETE	0x00
159 #define MSG_EXT_MESSAGE		0x01
160 #define	MSG_SAVE_DATA_PTR	0x02
161 #define	MSG_RESTORE_PTR		0x03
162 #define	MSG_DISCONNECT		0x04
163 #define	MSG_INIT_DETECT_ERROR	0x05
164 #define	MSG_ABORT		0x06
165 #define	MSG_REJECT		0x07
166 #define	MSG_NOOP		0x08
167 #define	MSG_PARITY_ERROR	0x09
168 #define	MSG_BUS_DEVICE_RESET	0x0C
169 #define	MSG_IDENTIFY		0x80
170 #define	MSG_IDENTIFY_DR		0xc0	/* (disconnect/reconnect allowed) */
171 #define	MSG_SYNC_REQ 		0x01
172 
173 /* SCSI Commands */
174 
175 #define CMD_TEST_UNIT_READY	0x00
176 #define CMD_REQUEST_SENSE	0x03
177 #define	CMD_INQUIRY		0x12
178 #define CMD_SEND_DIAGNOSTIC	0x1D
179 
180 #define CMD_REWIND		0x01
181 #define CMD_REZERO		0x01
182 #define CMD_FORMAT_UNIT		0x04
183 #define CMD_READ_BLOCK_LIMITS	0x05
184 #define CMD_REASSIGN_BLOCKS	0x07
185 #define CMD_READ		0x08
186 #define CMD_WRITE		0x0A
187 #define CMD_WRITE_FILEMARK	0x10
188 #define CMD_SPACE		0x11
189 #define CMD_MODE_SELECT		0x15
190 #define CMD_RELEASE_UNIT	0x17
191 #define CMD_ERASE		0x19
192 #define CMD_MODE_SENSE		0x1A
193 #define CMD_LOADUNLOAD		0x1B
194 #define CMD_RECEIVE_DIAG	0x1C
195 #define CMD_SEND_DIAG		0x1D
196 #define CMD_P_A_MEDIA_REMOVAL	0x1E
197 #define CMD_READ_CAPACITY	0x25
198 #define CMD_READ_EXT		0x28
199 #define CMD_WRITE_EXT		0x2A
200 #define CMD_READ_DEFECT_DATA	0x37
201 #define		SD_MANUFAC_DEFECTS	0x14000000
202 #define		SD_GROWN_DEFECTS	0x0c000000
203 #define CMD_READ_BUFFER		0x3B
204 #define CMD_WRITE_BUFFER	0x3C
205 #define CMD_READ_FULL		0xF0
206 #define CMD_MEDIA_TEST		0xF1
207 #define CMD_ACCESS_LOG		0xF2
208 #define CMD_WRITE_FULL		0xFC
209 #define CMD_MANAGE_PRIMARY	0xFD
210 #define CMD_EXECUTE_DATA	0xFE
211 
212 /* SCSI status bits */
213 
214 #define	STS_CHECKCOND	0x02	/* Check Condition (ie., read sense) */
215 #define	STS_CONDMET	0x04	/* Condition Met (ie., search worked) */
216 #define	STS_BUSY	0x08
217 #define	STS_INTERMED	0x10	/* Intermediate status sent */
218 #define	STS_EXT		0x80	/* Extended status valid */
219 
220 /* command descriptor blocks */
221 
222 struct scsi_cdb6 {
223 	u_char	cmd;		/* command code */
224 	u_char	lun:  3,	/* logical unit on ctlr */
225 		lbah: 5;	/* msb of read/write logical block addr */
226 	u_char	lbam;		/* middle byte of l.b.a. */
227 	u_char	lbal;		/* lsb of l.b.a. */
228 	u_char	len;		/* transfer length */
229 	u_char	xtra;
230 };
231 
232 struct scsi_cdb10 {
233 	u_char	cmd;		/* command code */
234 	u_char	lun: 3,		/* logical unit on ctlr */
235 		   : 4,
236 		rel: 1;		/* l.b.a. is relative addr if =1 */
237 	u_char	lbah;		/* msb of read/write logical block addr */
238 	u_char	lbahm;		/* high middle byte of l.b.a. */
239 	u_char	lbalm;		/* low middle byte of l.b.a. */
240 	u_char	lbal;		/* lsb of l.b.a. */
241 	u_char	reserved;
242 	u_char	lenh;		/* msb transfer length */
243 	u_char	lenl;		/* lsb transfer length */
244 	u_char	xtra;
245 };
246 
247 /* basic sense data */
248 
249 struct scsi_sense {
250 	u_char	valid: 1,	/* l.b.a. is valid */
251 		class: 3,
252 		code:  4;
253 	u_char	vu:    4,	/* vendor unique */
254 		lbah:  4;
255 	u_char	lbam;
256 	u_char	lbal;
257 };
258 
259 struct scsi_xsense {
260 	u_char	valid: 1,	/* l.b.a. is valid */
261 		class: 3,
262 		code:  4;
263 	u_char	segment;
264 	u_char	filemark: 1,
265 		eom:      1,
266 		ili:      1,	/* illegal length indicator */
267 		rsvd:	  1,
268 		key:	  4;
269 	u_char	info1;
270 	u_char	info2;
271 	u_char	info3;
272 	u_char	info4;
273 	u_char	len;		/* additional sense length */
274 };
275 
276 /* inquiry data */
277 struct scsi_inquiry {
278 	u_char	type;
279 	u_char	qual;
280 	u_char	version;
281 	u_char	rsvd;
282 	u_char	len;
283 	char	class[3];
284 	char	vendor_id[8];
285 	char	product_id[16];
286 	char	rev[4];
287 };
288 
289 struct scsi_format_parms {		/* physical BFI format */
290 	u_short	reserved;
291 	u_short	list_len;
292 	struct defect {
293 		unsigned cyl  : 24;
294 		unsigned head : 8;
295 		long	bytes_from_index;
296 	} defect[127];
297 };
298 
299 #ifdef _KERNEL
300 extern struct scsi_format_parms format_parms;
301 #endif
302 
303 struct scsi_reassign_parms {
304 	u_short	reserved;
305 	u_short	list_len;	/* length in bytes of defects only */
306 	struct new_defect {
307 		unsigned lba;	/* logical block address */
308 	} new_defect[2];
309 };
310 
311 #ifdef _KERNEL
312 extern struct scsi_reassign_parms reassign_parms;
313 #endif
314 
315 struct scsi_modesel_hdr {
316 	u_char	rsvd1;
317 	u_char	media_type;
318 	u_char 	rsvd2;
319 	u_char	block_desc_len;
320 	u_int	density		: 8;
321 	u_int	number_blocks	:24;
322 	u_int	rsvd3		: 8;
323 	u_int	block_length	:24;
324 };
325 
326 struct scsi_modesense_hdr {
327 	u_char	len;
328 	u_char	media_type;
329 	u_char 	wp    : 1;
330 	u_char 	rsvd1 : 7;
331 	u_char	block_desc_len;
332 	u_int	density		: 8;
333 	u_int	number_blocks	:24;
334 	u_int	rsvd2		: 8;
335 	u_int	block_length	:24;
336 };
337 
338 /*
339  * Mode Select / Mode sense "pages"
340  */
341 
342 /*
343  * Page One - Error Recovery Parameters
344  */
345 struct scsi_err_recovery {
346 	u_char	page_savable	: 1;	/* save parameters */
347 	u_char	reserved	: 1;
348 	u_char	page_code	: 6;	/* = 0x01 */
349 	u_char	page_length;		/* = 6 */
350 	u_char	awre		: 1;	/* auto write realloc enabled */
351 	u_char	arre		: 1;	/* auto read realloc enabled */
352 	u_char	tb		: 1;	/* transfer block */
353 	u_char 	rc		: 1;	/* read continuous */
354 	u_char	eec		: 1;	/* enable early correction */
355 	u_char	per		: 1;	/* post error */
356 	u_char	dte		: 1;	/* disable transfer on error */
357 	u_char	dcr		: 1;	/* disable correction */
358 	u_char	retry_count;
359 	u_char	correction_span;
360 	u_char	head_offset_count;
361 	u_char	strobe_offset_count;
362 	u_char	recovery_time_limit;
363 };
364 
365 /*
366  * Page Two - Disconnect / Reconnect Control Parameters
367  */
368 struct scsi_disco_reco {
369 	u_char	page_savable	: 1;	/* save parameters */
370 	u_char	rsvd		: 1;
371 	u_char	page_code	: 6;	/* = 0x02 */
372 	u_char	page_length;		/* = 10 */
373 	u_char	buffer_full_ratio;	/* write, how full before reconnect? */
374 	u_char	buffer_empty_ratio;	/* read, how full before reconnect? */
375 
376 	u_short	bus_inactivity_limit;	/* how much bus time for busy */
377 	u_short	disconnect_time_limit;	/* min to remain disconnected */
378 	u_short	connect_time_limit;	/* min to remain connected */
379 	u_short	reserved_1;
380 };
381 
382 /*
383  * Page Three - Direct Access Device Format Parameters
384  */
385 struct scsi_format {
386 	u_char	page_savable	: 1;	/* save parameters */
387 	u_char	rsvd		: 1;
388 	u_char	page_code	: 6;	/* = 0x03 */
389 	u_char	page_length;		/* = 22 */
390 	u_short	tracks_per_zone;	/*  Handling of Defects Fields */
391 	u_short	alt_sect_zone;
392 	u_short alt_tracks_zone;
393 	u_short	alt_tracks_vol;
394 	u_short	sect_track;		/* Track Format Field */
395 	u_short data_sect;		/* Sector Format Fields */
396 	u_short	interleave;
397 	u_short	track_skew_factor;
398 	u_short	cyl_skew_factor;
399 	u_char	ssec		: 1;	/* Drive Type Field */
400 	u_char	hsec		: 1;
401 	u_char	rmb		: 1;
402 	u_char	surf		: 1;
403 	u_char	ins		: 1;
404 	u_char	reserved_1	: 3;
405 	u_char	reserved_2;
406 	u_char	reserved_3;
407 	u_char	reserved_4;
408 };
409 
410 /*
411  * Page Four - Rigid Disk Drive Geometry Parameters
412  */
413 struct scsi_geometry {
414 	u_char	page_savable	: 1;	/* save parameters */
415 	u_char	rsvd		: 1;
416 	u_char	page_code	: 6;	/* = 0x04 */
417 	u_char	page_length;		/* = 18 */
418 	u_char	cyl_ub;			/* number of cylinders */
419 	u_char	cyl_mb;
420 	u_char	cyl_lb;
421 	u_char	heads;			/* number of heads */
422 	u_char	precomp_cyl_ub;		/* cylinder to start precomp */
423 	u_char	precomp_cyl_mb;
424 	u_char	precomp_cyl_lb;
425 	u_char	current_cyl_ub;		/* cyl to start reduced current */
426 	u_char	current_cyl_mb;
427 	u_char	current_cyl_lb;
428 	u_short	step_rate;		/* drive step rate */
429 	u_char	landing_cyl_ub;		/* landing zone cylinder */
430 	u_char	landing_cyl_mb;
431 	u_char	landing_cyl_lb;
432 	u_char	reserved_1;
433 	u_char	reserved_2;
434 	u_char	reserved_3;
435 };
436 
437 /*
438  * Page 0x38 - Cache Control Parameters
439  */
440 struct scsi_cache {
441 	u_char	page_savable	: 1;	/* save parameters */
442 	u_char	rsvd		: 1;
443 	u_char	page_code	: 6;	/* = 0x38 */
444 	u_char	page_length;		/* = 14 */
445 	u_char rsvd_1	: 1;
446 	u_char wie	: 1; 		/* write index enable */
447 	u_char rsvd_2	: 1;
448 	u_char ce	: 1; 		/* cache enable */
449 	u_char table_size : 4;
450 	u_char	prefetch_threshold;
451 	u_char	maximum_threshold;
452 	u_char	maximumprefetch_multiplier;
453 	u_char	minimum_threshold;
454 	u_char	minimum_prefetch_multiplier;
455 	u_char	reserved[8];
456 };
457 
458 /*
459  * Control for SCSI "format" mode.
460  *
461  * "Format" mode allows a privileged process to issue direct SCSI
462  * commands to a drive (it is intended primarily to allow on-line
463  * formatting).  SDIOCSFORMAT with a non-zero arg will put the drive
464  * into format mode; a zero arg will take it out.  When in format
465  * mode, only the process that issued the SDIOCFORMAT can read or
466  * write the drive.
467  *
468  * In format mode, process is expected to
469  *	- do SDIOCSCSICOMMAND to supply cdb for next SCSI op
470  *	- do read or write as appropriate for cdb
471  *	- if i/o error, optionally do SDIOCSENSE to get completion
472  *	  status and sense data from last scsi operation.
473  */
474 
475 struct scsi_fmt_cdb {
476 	int len;		/* cdb length (in bytes) */
477 	u_char cdb[28];		/* cdb to use on next read/write */
478 };
479 
480 struct scsi_fmt_sense {
481 	u_int status;		/* completion status of last op */
482 	u_char sense[28];	/* sense data (if any) from last op */
483 };
484 
485 #define	SDIOCSFORMAT		_IOW('S', 0x1, int)
486 #define	SDIOCGFORMAT		_IOR('S', 0x2, int)
487 #define	SDIOCSCSICOMMAND	_IOW('S', 0x3, struct scsi_fmt_cdb)
488 #define	SDIOCSENSE		_IOR('S', 0x4, struct scsi_fmt_sense)
489