xref: /illumos-gate/usr/src/cmd/format/ctlr_scsi.h (revision 9ca9c420)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5e8fb11a1Sshidokht  * Common Development and Distribution License (the "License").
6e8fb11a1Sshidokht  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*9ca9c420SSheng-Liang Eric Zhang  * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef	_CTLR_SCSI_H
267c478bd9Sstevel@tonic-gate #define	_CTLR_SCSI_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
297c478bd9Sstevel@tonic-gate extern "C" {
307c478bd9Sstevel@tonic-gate #endif
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/buf.h>
337c478bd9Sstevel@tonic-gate #include <sys/scsi/scsi.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Rounded parameter, as returned in Extended Sense information
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #define	ROUNDED_PARAMETER	0x37
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Timeout Value during formatting
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate #ifndef	SHRT_MAX
457c478bd9Sstevel@tonic-gate #define	SHRT_MAX	32767
467c478bd9Sstevel@tonic-gate #endif
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Mode sense/select page header information
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate struct scsi_ms_header {
527c478bd9Sstevel@tonic-gate 	struct mode_header	mode_header;
537c478bd9Sstevel@tonic-gate 	struct block_descriptor	block_descriptor;
547c478bd9Sstevel@tonic-gate };
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * Mode Sense Page Control
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate #define	MODE_SENSE_PC_CURRENT		(0 << 6)
607c478bd9Sstevel@tonic-gate #define	MODE_SENSE_PC_CHANGEABLE	(1 << 6)
617c478bd9Sstevel@tonic-gate #define	MODE_SENSE_PC_DEFAULT		(2 << 6)
627c478bd9Sstevel@tonic-gate #define	MODE_SENSE_PC_SAVED		(3 << 6)
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Mode Select options
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate #define	MODE_SELECT_SP			0x01
687c478bd9Sstevel@tonic-gate #define	MODE_SELECT_PF			0x10
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * Minimum length of Request Sense data that we can accept
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate #define	MIN_REQUEST_SENSE_LEN		18
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * "impossible" status value
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #define	IMPOSSIBLE_SCSI_STATUS		0xff
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * Convert a three-byte triplet into an int
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	TRIPLET(u, m, l)	((int)((((u))&0xff<<16) + \
867c478bd9Sstevel@tonic-gate 				(((m)&0xff)<<8) + (l&0xff)))
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Define the amount of slop we can tolerate on a SCSI-2 mode sense.
907c478bd9Sstevel@tonic-gate  * Usually we try to deal with just the common subset between the
917c478bd9Sstevel@tonic-gate  * the SCSI-2 structure and the CCS structure.  The length of the
927c478bd9Sstevel@tonic-gate  * data returned can vary between targets, so being tolerant gives
937c478bd9Sstevel@tonic-gate  * gives us a higher chance of success.
947c478bd9Sstevel@tonic-gate  */
957c478bd9Sstevel@tonic-gate #define	PAGE1_SLOP		5
967c478bd9Sstevel@tonic-gate #define	PAGE2_SLOP		6
977c478bd9Sstevel@tonic-gate #define	PAGE3_SLOP		3
987c478bd9Sstevel@tonic-gate #define	PAGE4_SLOP		8
997c478bd9Sstevel@tonic-gate #define	PAGE8_SLOP		8
1007c478bd9Sstevel@tonic-gate #define	PAGE38_SLOP		8
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Minimum lengths of a particular SCSI-2 mode sense page that
1047c478bd9Sstevel@tonic-gate  * we can deal with.  We must reject anything less than this.
1057c478bd9Sstevel@tonic-gate  */
1067c478bd9Sstevel@tonic-gate #define	MIN_PAGE1_LEN		(sizeof (struct mode_err_recov)-PAGE1_SLOP)
1077c478bd9Sstevel@tonic-gate #define	MIN_PAGE2_LEN		(sizeof (struct mode_disco_reco)-PAGE2_SLOP)
1087c478bd9Sstevel@tonic-gate #define	MIN_PAGE3_LEN		(sizeof (struct mode_format)-PAGE3_SLOP)
1097c478bd9Sstevel@tonic-gate #define	MIN_PAGE4_LEN		(sizeof (struct mode_geometry)-PAGE4_SLOP)
1107c478bd9Sstevel@tonic-gate #define	MIN_PAGE8_LEN		(sizeof (struct mode_cache)-PAGE8_SLOP)
1117c478bd9Sstevel@tonic-gate #define	MIN_PAGE38_LEN		(sizeof (struct mode_cache_ccs)-PAGE38_SLOP)
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * Macro to extract the length of a mode sense page
1157c478bd9Sstevel@tonic-gate  * as returned by a target.
1167c478bd9Sstevel@tonic-gate  */
1177c478bd9Sstevel@tonic-gate #define	MODESENSE_PAGE_LEN(p)	(((int)((struct mode_page *)p)->length) + \
1187c478bd9Sstevel@tonic-gate 					sizeof (struct mode_page))
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Request this number of bytes for all mode senses.  Since the
1227c478bd9Sstevel@tonic-gate  * data returned is self-defining, we can accept anywhere from
1237c478bd9Sstevel@tonic-gate  * the minimum for a particular page, up to this maximum.
1247c478bd9Sstevel@tonic-gate  * Whatever the drive gives us, we return to the drive, delta'ed
1257c478bd9Sstevel@tonic-gate  * by whatever we want to change.
1267c478bd9Sstevel@tonic-gate  */
1277c478bd9Sstevel@tonic-gate #define	MAX_MODE_SENSE_SIZE		255
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #ifdef	__STDC__
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  *	Local prototypes for ANSI C compilers
1337c478bd9Sstevel@tonic-gate  */
1347c478bd9Sstevel@tonic-gate int	scsi_rdwr(int, int, diskaddr_t, int, caddr_t, int, int *);
1357c478bd9Sstevel@tonic-gate int	scsi_ex_man(struct defect_list *);
1367c478bd9Sstevel@tonic-gate int	scsi_ex_cur(struct defect_list *);
1377c478bd9Sstevel@tonic-gate int	scsi_ex_grown(struct defect_list *);
1387c478bd9Sstevel@tonic-gate int	uscsi_cmd(int, struct uscsi_cmd *, int);
1397c478bd9Sstevel@tonic-gate int	uscsi_mode_sense(int, int, int, caddr_t, int,
1407c478bd9Sstevel@tonic-gate 		struct scsi_ms_header *);
1417c478bd9Sstevel@tonic-gate int	uscsi_mode_select(int, int, int, caddr_t, int,
1427c478bd9Sstevel@tonic-gate 		struct scsi_ms_header *);
1437c478bd9Sstevel@tonic-gate int	uscsi_inquiry(int, caddr_t, int);
144*9ca9c420SSheng-Liang Eric Zhang int	uscsi_inquiry_page_86h(int, caddr_t, int);
1457c478bd9Sstevel@tonic-gate int	uscsi_read_capacity(int, struct scsi_capacity_16 *);
146*9ca9c420SSheng-Liang Eric Zhang int	uscsi_read_capacity_16(int, struct scsi_capacity_16 *);
1477c478bd9Sstevel@tonic-gate int	scsi_translate(int, struct scsi_bfi_defect *);
1487c478bd9Sstevel@tonic-gate int	scsi_dump_mode_sense_pages(int);
1497c478bd9Sstevel@tonic-gate int	scsi_supported_page(int);
1507c478bd9Sstevel@tonic-gate int	apply_chg_list(int, int, uchar_t *, uchar_t *, struct chg_list *);
1517c478bd9Sstevel@tonic-gate int	scsi_format_time(void);
152*9ca9c420SSheng-Liang Eric Zhang uint8_t	get_cur_protection_type(struct scsi_capacity_16 *);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate #else
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate #ifdef sparc
1577c478bd9Sstevel@tonic-gate int	scsi_ms_page1();
1587c478bd9Sstevel@tonic-gate int	scsi_ms_page2();
1597c478bd9Sstevel@tonic-gate int	scsi_ms_page3();
1607c478bd9Sstevel@tonic-gate int	scsi_ms_page4();
1617c478bd9Sstevel@tonic-gate int	scsi_read_defect_data();
1627c478bd9Sstevel@tonic-gate int	scsi_repair();
1637c478bd9Sstevel@tonic-gate #endif /* sparc */
1647c478bd9Sstevel@tonic-gate 
165b63e7ecbSAbhinandan Ekande int	scsi_rdwr();
1667c478bd9Sstevel@tonic-gate int	scsi_ck_format();
1677c478bd9Sstevel@tonic-gate int	scsi_ex_man();
1687c478bd9Sstevel@tonic-gate int	scsi_ex_cur();
1697c478bd9Sstevel@tonic-gate int	scsi_ex_grown();
1707c478bd9Sstevel@tonic-gate int	uscsi_cmd();
1717c478bd9Sstevel@tonic-gate int	uscsi_mode_sense();
1727c478bd9Sstevel@tonic-gate int	uscsi_mode_select();
1737c478bd9Sstevel@tonic-gate int	uscsi_inquiry();
1747c478bd9Sstevel@tonic-gate int	uscsi_read_capacity();
1757c478bd9Sstevel@tonic-gate int	scsi_translate();
1767c478bd9Sstevel@tonic-gate int	scsi_dump_mode_sense_pages();
1777c478bd9Sstevel@tonic-gate int	scsi_supported_page();
1787c478bd9Sstevel@tonic-gate int	apply_chg_list();
1797c478bd9Sstevel@tonic-gate int	scsi_format_time();
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate #endif	/* __STDC__ */
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate #endif
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate #endif	/* _CTLR_SCSI_H */
188