xref: /onnv-gate/usr/src/uts/common/sys/scsi/impl/commands.h (revision 12045:c8a185097d95)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52148Spd144616  * Common Development and Distribution License (the "License").
62148Spd144616  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21*12045SLi.He@Sun.COM 
220Sstevel@tonic-gate /*
23*12045SLi.He@Sun.COM  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_SCSI_IMPL_COMMANDS_H
270Sstevel@tonic-gate #define	_SYS_SCSI_IMPL_COMMANDS_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate /*
340Sstevel@tonic-gate  * Implementation dependent command definitions.
350Sstevel@tonic-gate  * This file is included by <sys/scsi/generic/commands.h>
360Sstevel@tonic-gate  */
370Sstevel@tonic-gate 
380Sstevel@tonic-gate /*
390Sstevel@tonic-gate  * Implementation dependent view of a SCSI command descriptor block
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate 
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate  * Standard SCSI control blocks definitions.
440Sstevel@tonic-gate  *
450Sstevel@tonic-gate  * These go in or out over the SCSI bus.
460Sstevel@tonic-gate  *
470Sstevel@tonic-gate  * The first 8 bits of the command block are the same for all
480Sstevel@tonic-gate  * defined command groups.  The first byte is an operation which consists
490Sstevel@tonic-gate  * of a command code component and a group code component.
500Sstevel@tonic-gate  *
510Sstevel@tonic-gate  * The group code determines the length of the rest of the command.
520Sstevel@tonic-gate  * Group 0 commands are 6 bytes, Group 1 and 2  are 10 bytes, Group 4
530Sstevel@tonic-gate  * are 16 bytes, and Group 5 are 12 bytes. Groups 3 is Reserved.
540Sstevel@tonic-gate  * Groups 6 and 7 are Vendor Unique.
550Sstevel@tonic-gate  *
560Sstevel@tonic-gate  */
570Sstevel@tonic-gate #define	CDB_SIZE	CDB_GROUP5	/* deprecated, do not use */
580Sstevel@tonic-gate #define	SCSI_CDB_SIZE	CDB_GROUP4	/* sizeof (union scsi_cdb) */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate union scsi_cdb {		/* scsi command description block */
610Sstevel@tonic-gate 	struct {
620Sstevel@tonic-gate 		uchar_t	cmd;		/* cmd code (byte 0) */
630Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
640Sstevel@tonic-gate 		uchar_t tag	:5;	/* rest of byte 1 */
650Sstevel@tonic-gate 		uchar_t lun	:3;	/* lun (byte 1) (reserved in SCSI-3) */
660Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
670Sstevel@tonic-gate 		uchar_t	lun	:3,	/* lun (byte 1) (reserved in SCSI-3) */
680Sstevel@tonic-gate 			tag	:5;	/* rest of byte 1 */
690Sstevel@tonic-gate #else
700Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
710Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
720Sstevel@tonic-gate 		union {
730Sstevel@tonic-gate 
740Sstevel@tonic-gate 		uchar_t	scsi[SCSI_CDB_SIZE-2];
750Sstevel@tonic-gate 		/*
760Sstevel@tonic-gate 		 *	G R O U P   0   F O R M A T (6 bytes)
770Sstevel@tonic-gate 		 */
780Sstevel@tonic-gate #define		scc_cmd		cdb_un.cmd
790Sstevel@tonic-gate #define		scc_lun		cdb_un.lun
800Sstevel@tonic-gate #define		g0_addr2	cdb_un.tag
810Sstevel@tonic-gate #define		g0_addr1	cdb_un.sg.g0.addr1
820Sstevel@tonic-gate #define		g0_addr0	cdb_un.sg.g0.addr0
830Sstevel@tonic-gate #define		g0_count0	cdb_un.sg.g0.count0
840Sstevel@tonic-gate #define		g0_vu_1		cdb_un.sg.g0.vu_57
850Sstevel@tonic-gate #define		g0_vu_0		cdb_un.sg.g0.vu_56
860Sstevel@tonic-gate #define		g0_naca		cdb_un.sg.g0.naca
870Sstevel@tonic-gate #define		g0_flag		cdb_un.sg.g0.flag
880Sstevel@tonic-gate #define		g0_link		cdb_un.sg.g0.link
890Sstevel@tonic-gate 	/*
900Sstevel@tonic-gate 	 * defines for SCSI tape cdb.
910Sstevel@tonic-gate 	 */
920Sstevel@tonic-gate #define		t_code		cdb_un.tag
930Sstevel@tonic-gate #define		high_count	cdb_un.sg.g0.addr1
940Sstevel@tonic-gate #define		mid_count	cdb_un.sg.g0.addr0
950Sstevel@tonic-gate #define		low_count	cdb_un.sg.g0.count0
960Sstevel@tonic-gate 		struct scsi_g0 {
970Sstevel@tonic-gate 			uchar_t addr1;	/* middle part of address */
980Sstevel@tonic-gate 			uchar_t addr0;	/* low part of address */
990Sstevel@tonic-gate 			uchar_t count0;	/* usually block count */
1000Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
1010Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows 	*/
1020Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done 	*/
1030Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA  		*/
1040Sstevel@tonic-gate 			uchar_t rsvd	:3; /* reserved 		*/
1050Sstevel@tonic-gate 			uchar_t vu_56	:1; /* vendor unique (byte 5 bit6) */
1060Sstevel@tonic-gate 			uchar_t vu_57	:1; /* vendor unique (byte 5 bit7) */
1070Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
1080Sstevel@tonic-gate 			uchar_t vu_57	:1; /* vendor unique (byte 5 bit 7) */
1090Sstevel@tonic-gate 			uchar_t vu_56	:1; /* vendor unique (byte 5 bit 6) */
1100Sstevel@tonic-gate 			uchar_t rsvd	:3; /* reserved */
1110Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA  		*/
1120Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done */
1130Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows */
1140Sstevel@tonic-gate #else
1150Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
1160Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
1170Sstevel@tonic-gate 		} g0;
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate 		/*
1210Sstevel@tonic-gate 		 *	G R O U P   1, 2   F O R M A T  (10 byte)
1220Sstevel@tonic-gate 		 */
1230Sstevel@tonic-gate #define		g1_reladdr	cdb_un.tag
1240Sstevel@tonic-gate #define		g1_rsvd0	cdb_un.sg.g1.rsvd1
1250Sstevel@tonic-gate #define		g1_addr3	cdb_un.sg.g1.addr3	/* msb */
1260Sstevel@tonic-gate #define		g1_addr2	cdb_un.sg.g1.addr2
1270Sstevel@tonic-gate #define		g1_addr1	cdb_un.sg.g1.addr1
1280Sstevel@tonic-gate #define		g1_addr0	cdb_un.sg.g1.addr0	/* lsb */
1290Sstevel@tonic-gate #define		g1_count1	cdb_un.sg.g1.count1	/* msb */
1300Sstevel@tonic-gate #define		g1_count0	cdb_un.sg.g1.count0	/* lsb */
1310Sstevel@tonic-gate #define		g1_vu_1		cdb_un.sg.g1.vu_97
1320Sstevel@tonic-gate #define		g1_vu_0		cdb_un.sg.g1.vu_96
1330Sstevel@tonic-gate #define		g1_naca		cdb_un.sg.g1.naca
1340Sstevel@tonic-gate #define		g1_flag		cdb_un.sg.g1.flag
1350Sstevel@tonic-gate #define		g1_link		cdb_un.sg.g1.link
1360Sstevel@tonic-gate 		struct scsi_g1 {
1370Sstevel@tonic-gate 			uchar_t addr3;	/* most sig. byte of address */
1380Sstevel@tonic-gate 			uchar_t addr2;
1390Sstevel@tonic-gate 			uchar_t addr1;
1400Sstevel@tonic-gate 			uchar_t addr0;
1410Sstevel@tonic-gate 			uchar_t rsvd1;	/* reserved (byte 6) */
1420Sstevel@tonic-gate 			uchar_t count1;	/* transfer length (msb) */
1430Sstevel@tonic-gate 			uchar_t count0;	/* transfer length (lsb) */
1440Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
1450Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows 	*/
1460Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done 	*/
1470Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
1480Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved 		*/
1490Sstevel@tonic-gate 			uchar_t vu_96	:1; /* vendor unique (byte 9 bit6) */
1500Sstevel@tonic-gate 			uchar_t vu_97	:1; /* vendor unique (byte 9 bit7) */
1510Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
1520Sstevel@tonic-gate 			uchar_t vu_97	:1; /* vendor unique (byte 9 bit 7) */
1530Sstevel@tonic-gate 			uchar_t vu_96	:1; /* vendor unique (byte 9 bit 6) */
1540Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved */
1550Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
1560Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done */
1570Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows */
1580Sstevel@tonic-gate #else
1590Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
1600Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
1610Sstevel@tonic-gate 		} g1;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 		/*
1640Sstevel@tonic-gate 		 *	G R O U P   4   F O R M A T  (16 byte)
1650Sstevel@tonic-gate 		 */
1660Sstevel@tonic-gate #define		g4_reladdr		cdb_un.tag
1670Sstevel@tonic-gate #define		g4_addr3		cdb_un.sg.g4.addr3	/* msb */
1680Sstevel@tonic-gate #define		g4_addr2		cdb_un.sg.g4.addr2
1690Sstevel@tonic-gate #define		g4_addr1		cdb_un.sg.g4.addr1
1700Sstevel@tonic-gate #define		g4_addr0		cdb_un.sg.g4.addr0	/* lsb */
1710Sstevel@tonic-gate #define		g4_addtl_cdb_data3	cdb_un.sg.g4.addtl_cdb_data3
1720Sstevel@tonic-gate #define		g4_addtl_cdb_data2	cdb_un.sg.g4.addtl_cdb_data2
1730Sstevel@tonic-gate #define		g4_addtl_cdb_data1	cdb_un.sg.g4.addtl_cdb_data1
1740Sstevel@tonic-gate #define		g4_addtl_cdb_data0	cdb_un.sg.g4.addtl_cdb_data0
1750Sstevel@tonic-gate #define		g4_count3		cdb_un.sg.g4.count3	/* msb */
1760Sstevel@tonic-gate #define		g4_count2		cdb_un.sg.g4.count2
1770Sstevel@tonic-gate #define		g4_count1		cdb_un.sg.g4.count1
1780Sstevel@tonic-gate #define		g4_count0		cdb_un.sg.g4.count0	/* lsb */
1790Sstevel@tonic-gate #define		g4_rsvd0		cdb_un.sg.g4.rsvd1
1800Sstevel@tonic-gate #define		g4_vu_1			cdb_un.sg.g4.vu_157
1810Sstevel@tonic-gate #define		g4_vu_0			cdb_un.sg.g4.vu_156
1820Sstevel@tonic-gate #define		g4_naca			cdb_un.sg.g4.naca
1830Sstevel@tonic-gate #define		g4_flag			cdb_un.sg.g4.flag
1840Sstevel@tonic-gate #define		g4_link			cdb_un.sg.g4.link
1850Sstevel@tonic-gate 		struct scsi_g4 {
1860Sstevel@tonic-gate 			uchar_t addr3;	/* most sig. byte of address */
1870Sstevel@tonic-gate 			uchar_t addr2;
1880Sstevel@tonic-gate 			uchar_t addr1;
1890Sstevel@tonic-gate 			uchar_t addr0;
1900Sstevel@tonic-gate 			uchar_t addtl_cdb_data3;
1910Sstevel@tonic-gate 			uchar_t addtl_cdb_data2;
1920Sstevel@tonic-gate 			uchar_t addtl_cdb_data1;
1930Sstevel@tonic-gate 			uchar_t addtl_cdb_data0;
1940Sstevel@tonic-gate 			uchar_t count3;	/* transfer length (msb) */
1950Sstevel@tonic-gate 			uchar_t count2;
1960Sstevel@tonic-gate 			uchar_t count1;
1970Sstevel@tonic-gate 			uchar_t count0;	/* transfer length (lsb) */
1980Sstevel@tonic-gate 			uchar_t rsvd1;	/* reserved */
1990Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
2000Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows 	*/
2010Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done 	*/
2020Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
2030Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved 		*/
2040Sstevel@tonic-gate 			uchar_t vu_156	:1; /* vendor unique (byte 15 bit6) */
2050Sstevel@tonic-gate 			uchar_t vu_157	:1; /* vendor unique (byte 15 bit7) */
2060Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
2070Sstevel@tonic-gate 			uchar_t vu_157	:1; /* vendor unique (byte 15 bit 7) */
2080Sstevel@tonic-gate 			uchar_t vu_156	:1; /* vendor unique (byte 15 bit 6) */
2090Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved */
2100Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
2110Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done */
2120Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows */
2130Sstevel@tonic-gate #else
2140Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
2150Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
2160Sstevel@tonic-gate 		} g4;
2170Sstevel@tonic-gate 
2180Sstevel@tonic-gate 		/*
2190Sstevel@tonic-gate 		 *	G R O U P   5   F O R M A T  (12 byte)
2200Sstevel@tonic-gate 		 */
2210Sstevel@tonic-gate #define		scc5_reladdr	cdb_un.tag
2220Sstevel@tonic-gate #define		scc5_addr3	cdb_un.sg.g5.addr3	/* msb */
2230Sstevel@tonic-gate #define		scc5_addr2	cdb_un.sg.g5.addr2
2240Sstevel@tonic-gate #define		scc5_addr1	cdb_un.sg.g5.addr1
2250Sstevel@tonic-gate #define		scc5_addr0	cdb_un.sg.g5.addr0	/* lsb */
2260Sstevel@tonic-gate #define		scc5_count3	cdb_un.sg.g5.count3	/* msb */
2270Sstevel@tonic-gate #define		scc5_count2	cdb_un.sg.g5.count2
2280Sstevel@tonic-gate #define		scc5_count1	cdb_un.sg.g5.count1
2290Sstevel@tonic-gate #define		scc5_count0	cdb_un.sg.g5.count0	/* lsb */
2300Sstevel@tonic-gate #define		scc5_rsvd0	cdb_un.sg.g5.rsvd1
2310Sstevel@tonic-gate #define		scc5_vu_1	cdb_un.sg.g5.v117
2320Sstevel@tonic-gate #define		scc5_vu_0	cdb_un.sg.g5.v116
2330Sstevel@tonic-gate #define		scc5_naca	cdb_un.sg.g5.naca
2340Sstevel@tonic-gate #define		scc5_flag	cdb_un.sg.g5.flag
2350Sstevel@tonic-gate #define		scc5_link	cdb_un.sg.g5.link
2360Sstevel@tonic-gate 		struct scsi_g5 {
2370Sstevel@tonic-gate 			uchar_t addr3;	/* most sig. byte of address */
2380Sstevel@tonic-gate 			uchar_t addr2;
2390Sstevel@tonic-gate 			uchar_t addr1;
2400Sstevel@tonic-gate 			uchar_t addr0;
2410Sstevel@tonic-gate 			uchar_t count3;	/* most sig. byte of count */
2420Sstevel@tonic-gate 			uchar_t count2;
2430Sstevel@tonic-gate 			uchar_t count1;
2440Sstevel@tonic-gate 			uchar_t count0;
2450Sstevel@tonic-gate 			uchar_t rsvd1;	/* reserved */
2460Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
2470Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows 	*/
2480Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done 	*/
2490Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
2500Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved 		*/
2510Sstevel@tonic-gate 			uchar_t vu_116	:1; /* vendor unique (byte 11 bit6) */
2520Sstevel@tonic-gate 			uchar_t vu_117	:1; /* vendor unique (byte 11 bit7) */
2530Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
2540Sstevel@tonic-gate 			uchar_t vu_117	:1; /* vendor unique (byte 11 bit 7) */
2550Sstevel@tonic-gate 			uchar_t vu_116	:1; /* vendor unique (byte 11 bit 6) */
2560Sstevel@tonic-gate 			uchar_t rsvd0	:3; /* reserved */
2570Sstevel@tonic-gate 			uchar_t naca	:1; /* normal ACA		*/
2580Sstevel@tonic-gate 			uchar_t flag	:1; /* interrupt when done */
2590Sstevel@tonic-gate 			uchar_t link	:1; /* another command follows */
2600Sstevel@tonic-gate #else
2610Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
2620Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
2630Sstevel@tonic-gate 		} g5;
2640Sstevel@tonic-gate 		}sg;
2650Sstevel@tonic-gate 	} cdb_un;
2660Sstevel@tonic-gate 	uchar_t cdb_opaque[SCSI_CDB_SIZE]; /* addressed as opaque char array */
2670Sstevel@tonic-gate 	uint_t cdb_long[SCSI_CDB_SIZE / sizeof (uint_t)]; /* as a word array */
2680Sstevel@tonic-gate };
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate /*
2720Sstevel@tonic-gate  *	Various useful Macros for SCSI commands
2730Sstevel@tonic-gate  */
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate /*
2762148Spd144616  * defines for getting/setting fields in data received from or destined for
2772148Spd144616  * a SCSI device.  These macros are necessary (in place of BE16/BE32/BE64)
2782148Spd144616  * because the address to be read or written may not be on a proper alignment.
2792148Spd144616  */
2802148Spd144616 
2812148Spd144616 #define	SCSI_READ16(Sr16_Addr) \
2822148Spd144616 	(((uint16_t)*((uint8_t *)(Sr16_Addr)) << 8) | \
2836316Seschrock 	    ((uint16_t)*((uint8_t *)(Sr16_Addr)+1)))
2846316Seschrock 
2856316Seschrock #define	SCSI_READ24(Sr32_Addr)	\
2866316Seschrock 	(((uint32_t)*((uint8_t *)(Sr32_Addr)) << 16) | \
2876316Seschrock 	    ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 8) | \
2886316Seschrock 	    ((uint32_t)*((uint8_t *)(Sr32_Addr)+2)))
2892148Spd144616 
2902148Spd144616 #define	SCSI_READ32(Sr32_Addr) \
2912148Spd144616 	(((uint32_t)*((uint8_t *)(Sr32_Addr)) << 24) | \
2926316Seschrock 	    ((uint32_t)*((uint8_t *)(Sr32_Addr)+1) << 16) | \
2936316Seschrock 	    ((uint32_t)*((uint8_t *)(Sr32_Addr)+2) << 8) | \
2946316Seschrock 	    ((uint32_t)*((uint8_t *)(Sr32_Addr)+3)))
2956316Seschrock 
2966316Seschrock #define	SCSI_READ40(Sr64_Addr)	\
2976316Seschrock 	(((uint64_t)*((uint8_t *)(Sr64_Addr)) << 32) | \
2986316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 24) | \
2996316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 16) | \
3006316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 8) | \
3016316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+4)))
3026316Seschrock 
3036316Seschrock #define	SCSI_READ48(Sr64_Addr)	\
3046316Seschrock 	(((uint64_t)*((uint8_t *)(Sr64_Addr)) << 40) | \
3056316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 32) | \
3066316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 24) | \
3076316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 16) | \
3086316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 8) | \
3096316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+5)))
3102148Spd144616 
3112148Spd144616 #define	SCSI_READ64(Sr64_Addr) \
3122148Spd144616 	(((uint64_t)*((uint8_t *)(Sr64_Addr)) << 56) | \
3136316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+1) << 48) | \
3146316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+2) << 40) | \
3156316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+3) << 32) | \
3166316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+4) << 24) | \
3176316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+5) << 16) | \
3186316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+6) << 8) | \
3196316Seschrock 	    ((uint64_t)*((uint8_t *)(Sr64_Addr)+7)))
3202148Spd144616 
3212148Spd144616 #define	SCSI_WRITE16(Sr16_Addr, Sr16_Val) \
3226316Seschrock 	*((uint8_t *)(Sr16_Addr)) = (((uint16_t)(Sr16_Val) >> 8) & 0xff), \
3236316Seschrock 	*((uint8_t *)(Sr16_Addr)+1) = ((uint16_t)(Sr16_Val) & 0xff)
3246316Seschrock 
3256316Seschrock #define	SCSI_WRITE24(Sr24_Addr, Sr24_Val) \
3266316Seschrock 	SCSI_WRITE16((Sr24_Addr), ((Sr24_Val) & 0xffff00) >> 8),	\
3276316Seschrock 	*((uint8_t *)(Sr24_Addr)+2) = ((uint8_t)((Sr24_Val) & 0xff))
3282148Spd144616 
3292148Spd144616 #define	SCSI_WRITE32(Sr32_Addr, Sr32_Val) \
3306316Seschrock 	*(uint8_t *)(Sr32_Addr) = (((uint32_t)(Sr32_Val) >> 24) & 0xff), \
3316316Seschrock 	*((uint8_t *)(Sr32_Addr)+1) = \
3326316Seschrock 	    (((uint32_t)(Sr32_Val) >> 16) & 0xff), \
3336316Seschrock 	*((uint8_t *)(Sr32_Addr)+2) = (((uint32_t)(Sr32_Val) >> 8) & 0xff), \
3346316Seschrock 	*((uint8_t *)(Sr32_Addr)+3) = (((uint32_t)(Sr32_Val)) & 0xff)
3356316Seschrock 
3366316Seschrock #define	SCSI_WRITE40(Sr40_Addr, Sr40_Val) \
3376316Seschrock 	SCSI_WRITE32((Sr40_Addr), ((Sr40_Val) & 0xffffffff00ULL) >> 8),	\
3386316Seschrock 	*((uint8_t *)(Sr40_Addr)+4) = ((uint8_t)(Sr40_Val) & 0xff)
3396316Seschrock 
3406316Seschrock #define	SCSI_WRITE48(Sr48_Addr, Sr40_Val) \
3416316Seschrock 	SCSI_WRITE32((Sr48_Addr), ((Sr48_Val) & 0xffffffff0000ULL) >> 16), \
3426316Seschrock 	SCSI_WRITE16((uint8_t *)(Sr48_Addr)+4, (Sr40_Val) & 0xffff)
3432148Spd144616 
3442148Spd144616 #define	SCSI_WRITE64(Sr64_Addr, Sr64_Val) \
3456316Seschrock 	*(uint8_t *)(Sr64_Addr) = (((uint64_t)(Sr64_Val) >> 56) & 0xff), \
3466316Seschrock 	*((uint8_t *)(Sr64_Addr)+1) = \
3476316Seschrock 	    (((uint64_t)(Sr64_Val) >> 48) & 0xff), \
3486316Seschrock 	*((uint8_t *)(Sr64_Addr)+2) = \
3496316Seschrock 	    (((uint64_t)(Sr64_Val) >> 40) & 0xff), \
3506316Seschrock 	*((uint8_t *)(Sr64_Addr)+3) = \
3516316Seschrock 	    (((uint64_t)(Sr64_Val) >> 32) & 0xff), \
3526316Seschrock 	*((uint8_t *)(Sr64_Addr)+4) = \
3536316Seschrock 	    (((uint64_t)(Sr64_Val) >> 24) & 0xff), \
3546316Seschrock 	*((uint8_t *)(Sr64_Addr)+5) = \
3556316Seschrock 	    (((uint64_t)(Sr64_Val) >> 16) & 0xff), \
3566316Seschrock 	*((uint8_t *)(Sr64_Addr)+6) = \
3576316Seschrock 	    (((uint64_t)(Sr64_Val) >> 8) & 0xff), \
3586316Seschrock 	*((uint8_t *)(Sr64_Addr)+7) = (((uint64_t)(Sr64_Val)) & 0xff)
3596316Seschrock 
3606316Seschrock /*
3616316Seschrock  * These macros deal with unaligned data that crosses a byte boundary.
3626316Seschrock  */
3636316Seschrock #define	SCSI_MK8(ms, ls)	\
3646316Seschrock 	(((uint8_t)(ms) << 4) | (uint8_t)ls)
3656316Seschrock 
3666316Seschrock #define	SCSI_MK12_4_8(ms, ls)	\
3676316Seschrock 	(((uint16_t)(ms) << 8) | (uint16_t)(ls))
3686316Seschrock #define	SCSI_MK12_8_4(ms, ls)	\
3696316Seschrock 	(((uint16_t)(ms) << 4) | (uint16_t)(ls))
3706316Seschrock 
3716316Seschrock #define	SCSI_MK16_4_8_4(hi, mid, lo)	\
3726316Seschrock 	(((uint16_t)(hi) << 12) | ((uint16_t)(mid) << 4) | (uint16_t)(lo))
3736316Seschrock 
3746316Seschrock #define	SCSI_MK20_4_16(ms, ls)	\
3756316Seschrock 	(((uint32_t)(ms) << 16) | ((uint32_t)(ls)))
3766316Seschrock #define	SCSI_MK20_16_4(ms, ls)	\
3776316Seschrock 	(((uint32_t)(ms) << 4) | ((uint32_t)(ls)))
3786316Seschrock 
3796316Seschrock #define	SCSI_MK24_4_16_4(hi, mid, lo)	\
3806316Seschrock 	(((uint32_t)(hi) << 20) | ((uint32_t)(mid) << 4) | (uint32_t)(lo))
3816316Seschrock 
3826316Seschrock #define	SCSI_MK36_4_32(ms, ls)	\
3836316Seschrock 	(((uint64_t)(ms) << 32) | (uint64_t)(ls))
3846316Seschrock #define	SCSI_MK36_32_4(ms, ls)	\
3856316Seschrock 	(((uint64_t)(ms) << 4) | (uint64_t)(ls))
3862148Spd144616 
3872148Spd144616 /*
3880Sstevel@tonic-gate  * defines for getting/setting fields within the various command groups
3890Sstevel@tonic-gate  */
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate #define	GETCMD(cdb)		((cdb)->scc_cmd & 0x1F)
3920Sstevel@tonic-gate #define	GETGROUP(cdb)		(CDB_GROUPID((cdb)->scc_cmd))
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate #define	FORMG0COUNT(cdb, cnt)	(cdb)->g0_count0  = (cnt)
3950Sstevel@tonic-gate 
3960Sstevel@tonic-gate #define	FORMG0ADDR(cdb, addr) 	(cdb)->g0_addr2  = (addr) >> 16; \
3970Sstevel@tonic-gate 				(cdb)->g0_addr1  = ((addr) >> 8) & 0xFF; \
3980Sstevel@tonic-gate 				(cdb)->g0_addr0  = (addr) & 0xFF
3990Sstevel@tonic-gate 
4002314Smcneal #define	GETG0COUNT(cdb)		(cdb)->g0_count0
4012314Smcneal 
4022314Smcneal #define	GETG0ADDR(cdb)		((((cdb)->g0_addr2 & 0x1F) << 16) + \
4032314Smcneal 				((cdb)->g0_addr1 << 8) + ((cdb)->g0_addr0))
4040Sstevel@tonic-gate 
4050Sstevel@tonic-gate #define	GETG0TAG(cdb)		((cdb)->g0_addr2)
4060Sstevel@tonic-gate 
4070Sstevel@tonic-gate #define	FORMG0COUNT_S(cdb, cnt)	(cdb)->high_count  = (cnt) >> 16; \
4080Sstevel@tonic-gate 				(cdb)->mid_count = ((cnt) >> 8) & 0xFF; \
4090Sstevel@tonic-gate 				(cdb)->low_count = (cnt) & 0xFF
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate #define	FORMG1COUNT(cdb, cnt)	(cdb)->g1_count1 = ((cnt) >> 8); \
4120Sstevel@tonic-gate 				(cdb)->g1_count0 = (cnt) & 0xFF
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate #define	FORMG1ADDR(cdb, addr)	(cdb)->g1_addr3  = (addr) >> 24; \
4150Sstevel@tonic-gate 				(cdb)->g1_addr2  = ((addr) >> 16) & 0xFF; \
4160Sstevel@tonic-gate 				(cdb)->g1_addr1  = ((addr) >> 8) & 0xFF; \
4170Sstevel@tonic-gate 				(cdb)->g1_addr0  = (addr) & 0xFF
4180Sstevel@tonic-gate 
4192314Smcneal #define	GETG1COUNT(cdb)		(((cdb)->g1_count1 << 8) + ((cdb)->g1_count0))
4202314Smcneal 
4212314Smcneal #define	GETG1ADDR(cdb)		(((cdb)->g1_addr3 << 24) + \
4220Sstevel@tonic-gate 				((cdb)->g1_addr2 << 16) + \
4230Sstevel@tonic-gate 				((cdb)->g1_addr1 << 8)  + \
4242314Smcneal 				((cdb)->g1_addr0))
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate #define	GETG1TAG(cdb)		(cdb)->g1_reladdr
4270Sstevel@tonic-gate 
4280Sstevel@tonic-gate #define	FORMG4COUNT(cdb, cnt)	(cdb)->g4_count3 = ((cnt) >> 24); \
4290Sstevel@tonic-gate 				(cdb)->g4_count2 = ((cnt) >> 16) & 0xFF; \
4300Sstevel@tonic-gate 				(cdb)->g4_count1 = ((cnt) >> 8) & 0xFF; \
4310Sstevel@tonic-gate 				(cdb)->g4_count0 = (cnt) & 0xFF
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate #define	FORMG4LONGADDR(cdb, addr)	(cdb)->g4_addr3 = (addr) >> 56; \
4340Sstevel@tonic-gate 					(cdb)->g4_addr2 = \
4350Sstevel@tonic-gate 						((addr) >> 48) & 0xFF; \
4360Sstevel@tonic-gate 					(cdb)->g4_addr1 = \
4370Sstevel@tonic-gate 						((addr) >> 40) & 0xFF; \
4380Sstevel@tonic-gate 					(cdb)->g4_addr0 = \
4390Sstevel@tonic-gate 						((addr) >> 32) & 0xFF; \
4400Sstevel@tonic-gate 					(cdb)->g4_addtl_cdb_data3 = \
4410Sstevel@tonic-gate 						((addr) >> 24) & 0xFF; \
4420Sstevel@tonic-gate 					(cdb)->g4_addtl_cdb_data2 = \
4430Sstevel@tonic-gate 						((addr) >> 16) & 0xFF; \
4440Sstevel@tonic-gate 					(cdb)->g4_addtl_cdb_data1 = \
4450Sstevel@tonic-gate 						((addr) >> 8) & 0xFF; \
4460Sstevel@tonic-gate 					(cdb)->g4_addtl_cdb_data0 = \
4470Sstevel@tonic-gate 						(addr) & 0xFF
4480Sstevel@tonic-gate 
4492314Smcneal #define	GETG4COUNT(cdb)		(((cdb)->g4_count3 << 24) + \
4502314Smcneal 				((cdb)->g4_count2 << 16) + \
4512314Smcneal 				((cdb)->g4_count1 << 8) + \
4522314Smcneal 				((cdb)->g4_count0))
4532314Smcneal 
4542314Smcneal #define	GETG4LONGADDR(cdb)	(((diskaddr_t)(cdb)->g4_addr3 << 56) + \
4552314Smcneal 			((diskaddr_t)(cdb)->g4_addr2 << 48) + \
4562314Smcneal 			((diskaddr_t)(cdb)->g4_addr1 << 40) + \
4572314Smcneal 			((diskaddr_t)(cdb)->g4_addr0 << 32) + \
4582314Smcneal 			((diskaddr_t)(cdb)->g4_addtl_cdb_data3 << 24) + \
4592314Smcneal 			((diskaddr_t)(cdb)->g4_addtl_cdb_data2 << 16) + \
4602314Smcneal 			((diskaddr_t)(cdb)->g4_addtl_cdb_data1 << 8) + \
4612314Smcneal 			((diskaddr_t)(cdb)->g4_addtl_cdb_data0))
4622314Smcneal 
4630Sstevel@tonic-gate #define	FORMG4ADDR(cdb, addr)	(cdb)->g4_addr3 = (addr) >> 24; \
4640Sstevel@tonic-gate 				(cdb)->g4_addr2 = ((addr) >> 16) & 0xFF; \
4650Sstevel@tonic-gate 				(cdb)->g4_addr1 = ((addr) >> 8) & 0xFF; \
4660Sstevel@tonic-gate 				(cdb)->g4_addr0 = (addr) & 0xFF
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate #define	FORMG4ADDTL(cdb, addtl_cdb_data) (cdb)->g4_addtl_cdb_data3 = \
4690Sstevel@tonic-gate 					(addtl_cdb_data) >> 24; \
4700Sstevel@tonic-gate 				(cdb)->g4_addtl_cdb_data2 = \
4710Sstevel@tonic-gate 					((addtl_cdb_data) >> 16) & 0xFF; \
4720Sstevel@tonic-gate 				(cdb)->g4_addtl_cdb_data1 = \
4730Sstevel@tonic-gate 					((addtl_cdb_data) >> 8) & 0xFF; \
4740Sstevel@tonic-gate 				(cdb)->g4_addtl_cdb_data0 = \
4750Sstevel@tonic-gate 					(addtl_cdb_data) & 0xFF
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate #define	GETG4ADDR(cdb)		((cdb)->g4_addr3 << 24) + \
4780Sstevel@tonic-gate 				((cdb)->g4_addr2 << 16) + \
4790Sstevel@tonic-gate 				((cdb)->g4_addr1 << 8)  + \
4800Sstevel@tonic-gate 				((cdb)->g4_addr0)
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate #define	GETG4ADDRTL(cdb)	(((cdb)->g4_addtl_cdb_data3 << 24) + \
4830Sstevel@tonic-gate 				((cdb)->g4_addtl_cdb_data2 << 16) + \
4840Sstevel@tonic-gate 				((cdb)->g4_addtl_cdb_data1 << 8) + \
4850Sstevel@tonic-gate 				(cdb)->g4_addtl_cdb_data0)
4860Sstevel@tonic-gate 
4870Sstevel@tonic-gate #define	GETG4TAG(cdb)		(cdb)->g4_reladdr
4880Sstevel@tonic-gate 
4890Sstevel@tonic-gate #define	FORMG5COUNT(cdb, cnt)	(cdb)->scc5_count3 = ((cnt) >> 24); \
4900Sstevel@tonic-gate 				(cdb)->scc5_count2 = ((cnt) >> 16) & 0xFF; \
4910Sstevel@tonic-gate 				(cdb)->scc5_count1 = ((cnt) >> 8) & 0xFF; \
4920Sstevel@tonic-gate 				(cdb)->scc5_count0 = (cnt) & 0xFF
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate #define	FORMG5ADDR(cdb, addr)	(cdb)->scc5_addr3  = (addr) >> 24; \
4950Sstevel@tonic-gate 				(cdb)->scc5_addr2  = ((addr) >> 16) & 0xFF; \
4960Sstevel@tonic-gate 				(cdb)->scc5_addr1  = ((addr) >> 8) & 0xFF; \
4970Sstevel@tonic-gate 				(cdb)->scc5_addr0  = (addr) & 0xFF
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate #define	GETG5ADDR(cdb)		((cdb)->scc5_addr3 << 24) + \
5000Sstevel@tonic-gate 				((cdb)->scc5_addr2 << 16) + \
5010Sstevel@tonic-gate 				((cdb)->scc5_addr1 << 8)  + \
5020Sstevel@tonic-gate 				((cdb)->scc5_addr0)
5030Sstevel@tonic-gate 
5042684Smcneal #define	GETG5COUNT(cdb)		((cdb)->scc5_count3 << 24) + \
5052684Smcneal 				((cdb)->scc5_count2 << 16) + \
5062684Smcneal 				((cdb)->scc5_count1 << 8) + \
5072684Smcneal 				((cdb)->scc5_count0)
5082684Smcneal 
5090Sstevel@tonic-gate #define	GETG5TAG(cdb)		(cdb)->scc5_reladdr
5100Sstevel@tonic-gate 
5110Sstevel@tonic-gate 
5120Sstevel@tonic-gate /*
5130Sstevel@tonic-gate  * Shorthand macros for forming commands
5140Sstevel@tonic-gate  *
5150Sstevel@tonic-gate  * Works only with pre-SCSI-3 because they put lun as part of CDB.
5160Sstevel@tonic-gate  * scsi_setup_cdb() is the recommended interface.
5170Sstevel@tonic-gate  */
5180Sstevel@tonic-gate 
5190Sstevel@tonic-gate #define	MAKECOM_COMMON(pktp, devp, flag, cmd)	\
5200Sstevel@tonic-gate 	(pktp)->pkt_address = (devp)->sd_address, \
5210Sstevel@tonic-gate 	(pktp)->pkt_flags = (flag), \
5220Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_cmd = (cmd), \
5230Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->scc_lun = \
5240Sstevel@tonic-gate 	    (pktp)->pkt_address.a_lun
5250Sstevel@tonic-gate 
5260Sstevel@tonic-gate #define	MAKECOM_G0(pktp, devp, flag, cmd, addr, cnt)	\
5270Sstevel@tonic-gate 	MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
5280Sstevel@tonic-gate 	FORMG0ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
5290Sstevel@tonic-gate 	FORMG0COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
5300Sstevel@tonic-gate 
5310Sstevel@tonic-gate #define	MAKECOM_G0_S(pktp, devp, flag, cmd, cnt, fixbit)	\
5320Sstevel@tonic-gate 	MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
5330Sstevel@tonic-gate 	FORMG0COUNT_S(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt)), \
5340Sstevel@tonic-gate 	((union scsi_cdb *)(pktp)->pkt_cdbp)->t_code = (fixbit)
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate #define	MAKECOM_G1(pktp, devp, flag, cmd, addr, cnt)	\
5370Sstevel@tonic-gate 	MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
5380Sstevel@tonic-gate 	FORMG1ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
5390Sstevel@tonic-gate 	FORMG1COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
5400Sstevel@tonic-gate 
5410Sstevel@tonic-gate #define	MAKECOM_G5(pktp, devp, flag, cmd, addr, cnt)	\
5420Sstevel@tonic-gate 	MAKECOM_COMMON((pktp), (devp), (flag), (cmd)), \
5430Sstevel@tonic-gate 	FORMG5ADDR(((union scsi_cdb *)(pktp)->pkt_cdbp), (addr)), \
5440Sstevel@tonic-gate 	FORMG5COUNT(((union scsi_cdb *)(pktp)->pkt_cdbp), (cnt))
5450Sstevel@tonic-gate 
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate  * Direct access disk format defines and parameters.
5490Sstevel@tonic-gate  *
5500Sstevel@tonic-gate  * This is still pretty ugly and is mostly derived
5510Sstevel@tonic-gate  * from Emulex MD21 specific formatting.
5520Sstevel@tonic-gate  */
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate #define	fmt_parm_bits		g0_addr2	/* for format options */
5550Sstevel@tonic-gate #define	fmt_interleave		g0_count0	/* for encode interleave */
5560Sstevel@tonic-gate #define	defect_list_descrip	g1_addr3	/* list description bits */
5570Sstevel@tonic-gate 
5580Sstevel@tonic-gate /*
5590Sstevel@tonic-gate  * defines for value of fmt_parm_bits.
5600Sstevel@tonic-gate  */
5610Sstevel@tonic-gate 
5620Sstevel@tonic-gate #define	FPB_BFI			0x04	/* bytes-from-index fmt */
5630Sstevel@tonic-gate #define	FPB_CMPLT		0x08	/* full defect list provided */
5640Sstevel@tonic-gate #define	FPB_DATA		0x10	/* defect list data provided */
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate /*
5670Sstevel@tonic-gate  * Defines for value of defect_list_descrip.
5680Sstevel@tonic-gate  */
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate #define	DLD_MAN_DEF_LIST	0x10	/* manufacturer's defect list */
5710Sstevel@tonic-gate #define	DLD_GROWN_DEF_LIST	0x08	/* grown defect list */
5720Sstevel@tonic-gate #define	DLD_BLOCK_FORMAT	0x00	/* block format */
5730Sstevel@tonic-gate #define	DLD_BFI_FORMAT		0x04	/* bytes-from-index format */
5740Sstevel@tonic-gate #define	DLD_PS_FORMAT		0x05	/* physical sector format */
5750Sstevel@tonic-gate 
576*12045SLi.He@Sun.COM /*
577*12045SLi.He@Sun.COM  * Defines for value of CONTROL byte of cdb.
578*12045SLi.He@Sun.COM  */
579*12045SLi.He@Sun.COM #define	CDB_FLAG_NACA		0x04	/* naca flag */
5800Sstevel@tonic-gate 
5810Sstevel@tonic-gate /*
5820Sstevel@tonic-gate  * Disk defect list - used by format command.
5830Sstevel@tonic-gate  */
5840Sstevel@tonic-gate #define	RDEF_ALL	0	/* read all defects */
5850Sstevel@tonic-gate #define	RDEF_MANUF	1	/* read manufacturer's defects */
5860Sstevel@tonic-gate #define	RDEF_CKLEN	2	/* check length of manufacturer's list */
5870Sstevel@tonic-gate #define	ST506_NDEFECT	127	/* must fit in 1K controller buffer... */
5880Sstevel@tonic-gate #define	ESDI_NDEFECT	ST506_NDEFECT
5890Sstevel@tonic-gate 
5900Sstevel@tonic-gate struct scsi_bfi_defect {	/* defect in bytes from index format */
5910Sstevel@tonic-gate 	unsigned cyl  : 24;
5920Sstevel@tonic-gate 	unsigned head : 8;
5930Sstevel@tonic-gate 	int	bytes_from_index;
5940Sstevel@tonic-gate };
5950Sstevel@tonic-gate 
5960Sstevel@tonic-gate struct scsi_format_params {	/* BFI format list */
5970Sstevel@tonic-gate 	ushort_t reserved;
5980Sstevel@tonic-gate 	ushort_t length;
5990Sstevel@tonic-gate 	struct  scsi_bfi_defect list[ESDI_NDEFECT];
6000Sstevel@tonic-gate };
6010Sstevel@tonic-gate 
6020Sstevel@tonic-gate /*
6030Sstevel@tonic-gate  * Defect list returned by READ_DEFECT_LIST command.
6040Sstevel@tonic-gate  */
6050Sstevel@tonic-gate struct scsi_defect_hdr {	/* For getting defect list size */
6060Sstevel@tonic-gate 	uchar_t	reserved;
6070Sstevel@tonic-gate 	uchar_t	descriptor;
6080Sstevel@tonic-gate 	ushort_t length;
6090Sstevel@tonic-gate };
6100Sstevel@tonic-gate 
6110Sstevel@tonic-gate struct scsi_defect_list {	/* BFI format list */
6120Sstevel@tonic-gate 	uchar_t	reserved;
6130Sstevel@tonic-gate 	uchar_t	descriptor;
6140Sstevel@tonic-gate 	ushort_t length;
6150Sstevel@tonic-gate 	struct	scsi_bfi_defect list[ESDI_NDEFECT];
6160Sstevel@tonic-gate };
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate /*
6190Sstevel@tonic-gate  *
6200Sstevel@tonic-gate  * Direct Access device Reassign Block parameter
6210Sstevel@tonic-gate  *
6220Sstevel@tonic-gate  * Defect list format used by reassign block command (logical block format).
6230Sstevel@tonic-gate  *
6240Sstevel@tonic-gate  * This defect list is limited to 1 defect, as that is the only way we use it.
6250Sstevel@tonic-gate  *
6260Sstevel@tonic-gate  */
6270Sstevel@tonic-gate 
6280Sstevel@tonic-gate struct scsi_reassign_blk {
6290Sstevel@tonic-gate 	ushort_t reserved;
6300Sstevel@tonic-gate 	ushort_t length;	/* defect length in bytes (defects * 4) */
6310Sstevel@tonic-gate 	uint_t 	defect;		/* Logical block address of defect */
6320Sstevel@tonic-gate };
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate /*
6350Sstevel@tonic-gate  * Direct Access Device Capacity Structure -- 8 byte version
6360Sstevel@tonic-gate  */
6370Sstevel@tonic-gate 
6380Sstevel@tonic-gate struct scsi_capacity {
6390Sstevel@tonic-gate 	uint_t	capacity;
6400Sstevel@tonic-gate 	uint_t	lbasize;
6410Sstevel@tonic-gate };
6420Sstevel@tonic-gate 
6430Sstevel@tonic-gate /*
6440Sstevel@tonic-gate  * Direct Access Device Capacity Structure -- 16 byte version
6450Sstevel@tonic-gate  */
6460Sstevel@tonic-gate 
6470Sstevel@tonic-gate struct scsi_capacity_16 {
6480Sstevel@tonic-gate 	uint64_t	sc_capacity;
6490Sstevel@tonic-gate 	uint_t		sc_lbasize;
6500Sstevel@tonic-gate #if defined(_BIT_FIELDS_LTOH)
6510Sstevel@tonic-gate 	uchar_t 	sc_rto_en	:1;
6520Sstevel@tonic-gate 	uchar_t 	sc_prot_en	:1;
6530Sstevel@tonic-gate 	uchar_t 	sc_rsvd0	:6;
6540Sstevel@tonic-gate #elif defined(_BIT_FIELDS_HTOL)
6550Sstevel@tonic-gate 	uchar_t 	sc_rsvd0	:6;
6560Sstevel@tonic-gate 	uchar_t 	sc_prot_en	:1;
6570Sstevel@tonic-gate 	uchar_t 	sc_rto_en	:1;
6580Sstevel@tonic-gate #else
6590Sstevel@tonic-gate #error	One of _BIT_FIELDS_LTOH or _BIT_FIELDS_HTOL must be defined
6600Sstevel@tonic-gate #endif	/* _BIT_FIELDS_LTOH */
6610Sstevel@tonic-gate 	uchar_t 	sc_rsvd1[19];
6620Sstevel@tonic-gate };
6630Sstevel@tonic-gate 
6640Sstevel@tonic-gate #ifdef	_KERNEL
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate /*
6670Sstevel@tonic-gate  * Functional versions of the above macros, and other functions.
6680Sstevel@tonic-gate  * the makecom functions have been deprecated. Please use
6690Sstevel@tonic-gate  * scsi_setup_cdb()
6700Sstevel@tonic-gate  */
6710Sstevel@tonic-gate 
6720Sstevel@tonic-gate #ifdef  __STDC__
6730Sstevel@tonic-gate extern void 	makecom_g0(struct scsi_pkt *pkt, struct scsi_device *devp,
6740Sstevel@tonic-gate 				int flag, int cmd, int addr, int cnt);
6750Sstevel@tonic-gate extern void 	makecom_g0_s(struct scsi_pkt *pkt, struct scsi_device *devp,
6760Sstevel@tonic-gate 				int flag, int cmd, int cnt, int fixbit);
6770Sstevel@tonic-gate extern void 	makecom_g1(struct scsi_pkt *pkt, struct scsi_device *devp,
6780Sstevel@tonic-gate 				int flag, int cmd, int addr, int cnt);
6790Sstevel@tonic-gate extern void 	makecom_g5(struct scsi_pkt *pkt, struct scsi_device *devp,
6800Sstevel@tonic-gate 				int flag, int cmd, int addr, int cnt);
6810Sstevel@tonic-gate extern int	scsi_setup_cdb(union scsi_cdb *cdbp, uchar_t cmd, uint_t addr,
6820Sstevel@tonic-gate 				uint_t cnt, uint_t addtl_cdb_data);
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate #else   /* __STDC__ */
6850Sstevel@tonic-gate 
6860Sstevel@tonic-gate extern void 	makecom_g0();
6870Sstevel@tonic-gate extern void 	makecom_g0_s();
6880Sstevel@tonic-gate extern void 	makecom_g1();
6890Sstevel@tonic-gate extern void 	makecom_g5();
6900Sstevel@tonic-gate extern int	scsi_setup_cdb();
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate #endif  /* __STDC__ */
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate #endif /* _KERNEL */
6950Sstevel@tonic-gate 
6960Sstevel@tonic-gate #ifdef	__cplusplus
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate #endif
6990Sstevel@tonic-gate 
7000Sstevel@tonic-gate #endif	/* _SYS_SCSI_IMPL_COMMANDS_H */
701